google cloud messaging - Pass action to the app when the user click on notification on android devices -


how can pass information android application when user click notification when application not in foreground, example user message, notice getting notification, after user click navigate application, problem application opens in default state, want navigate messaging page first.

public class mygcmlistenerservice extends gcmlistenerservice {  private static final string tag = "mygcmlistenerservice"; private userdetails userdetails;  /**  * called when message received.  *  * @param senderid of sender.  * @param data data bundle containing message data key/value pairs.  *             set of keys use data.keyset().  */ // [start receive_message] @override public void onmessagereceived(string from, bundle data) {     string message = data.getstring("message");     log.d(tag, "from: " + from);     log.d(tag, "message: " + message);     log.d(tag, "data" + data);      /**      * in cases may useful show notification indicating user      * message received.      */     if(isapponforeground()){         //toast.maketext(getapplication(), data.tostring(),toast.length_long).show();     }else{         sendnotification(message);         return;         //sendnotification("you not in app");     }  }  /**  * create , show simple notification containing received gcm message.  *  * @param message gcm message received.  */ private void sendnotification(string message) {     intent intent = new intent(this, mainactivity.class);     intent.addflags(intent.flag_activity_clear_top);     pendingintent pendingintent = pendingintent.getactivity(this, 0 /* request code */, intent,             pendingintent.flag_one_shot);      uri defaultsounduri = ringtonemanager.getdefaulturi(ringtonemanager.type_notification);     notificationcompat.builder notificationbuilder = new notificationcompat.builder(this)             .setsmallicon(r.drawable.two_grow_icon)             .setcontenttitle("test")             .setcontenttext(message)             .setautocancel(true)             .setsound(defaultsounduri)             .setcontentintent(pendingintent);      notificationmanager notificationmanager =             (notificationmanager) getsystemservice(context.notification_service);      notificationmanager.notify(0 /* id of notification */, notificationbuilder.build()); }  //function check if application in foreground private boolean isapponforeground() {     activitymanager activitymanager = (activitymanager) getsystemservice(context.activity_service);     list<activitymanager.runningappprocessinfo> appprocesses = activitymanager.getrunningappprocesses();     if (appprocesses == null) {         return false;     }     final string packagename = getpackagename();     (activitymanager.runningappprocessinfo appprocess : appprocesses) {         if (appprocess.importance == activitymanager.runningappprocessinfo.importance_foreground && appprocess.processname.equals(packagename)) {             return true;         }     }     return false; } 

}


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -