Android - how can I send a notification using GCM with download instructions?

I can create push notifications. But for now, I can just make people land on the main screen.

How can I send people to a specific activity? And is it possible to also add some parameter, for example item_id, so that the activity knows what data to load?

Or, if there is a good tutorial for this, that's great too. In fact, I can not find much useful information on this subject in googling.

In my GCMIntentService, I have this method:

      @Override
      protected void onMessage(Context ctxt, Intent message) 
      {           
        Bundle extras=message.getExtras();

        try
        {
            String question_id = extras.getString("question_id");
//          SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences( this );
//          Intent intent = new Intent(ctxt, QuestionActivity.class);

            generateNotification(ctxt, extras.getString("message"), "New Message"  );           
        }
        catch ( Exception e )
        {
        }
      }

But I'm not sure how to change generateNotification to also signal what activity a person should land on. Thank!

+5
source share
2

UPDATE: JSON, .

:

{
   "registration_ids" : ["APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx..."],
   "data": {
       "stuff": "100",
       "more": "abc"
   },
}

, intent.getExtras().getString("stuff").

.

generateNotifcation():

private static void generateNotification(Context context, String message) {
    NotificationManager notificationManager = (NotificationManager)
        context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.ic_launcher, message, when);
    String title = "...";


    //get id from json here and decide which activity to go to...
    Intent notificationIntent = new Intent(context, someClass.class);


    notificationIntent.putExtra("message",message);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.defaults|=Notification.DEFAULT_VIBRATE;
    notificationManager.notify(0, notification);
}
+10

, item_id. , . Apple Push, , , message, String ( 4096 ).

Activity , , .

+3

All Articles