android - Do not show notification if certain activity is being displayed. Execute this activity's method instead -


I downloaded the GCM example code and it works fine.

I have added two activities and now your project contais the following files:

  • GcmBroadcastReceiver (WakefulBroadcastReceiver extends) (original)

  • GcmIntentService (IntentService extends) (original)

  • MainActivity

  • ActivityListView

    The original code when the GCM message arrives, the notification is always shown, but now I have to inform that when ActivityListView activity is not being displayed.

    If the app is displaying ActivityListView, the notification should not be shown and an ActivityListView method should be executed instead

    I mean I need some code like this.

      Secure void onHandleIntent {intent of intent} {bundle extras = intent.getExtras (); If (ActivityListView is being displayed) {ActivityListView.mymethod (additional); } Other {sendNotification ("Received:" + extras.toString ()); }}   

    GcmIntentService now looks:

      Public class GcmIntentService extends IntentService {..... @Override zero onHandleIntent protected {bundle} Extras = Intestine Jaay Extras (); GoogleCloudMessaging GCM = GoogleCloudMessaging.getInstance (this); String Message Type = GCM.GetMessage Type (Intent); If (! Extras.ISTT ()) {// has the effect of the basis of the baking bundle ........ Remittance Notification ("Received:" + Extras .Stustring ()); }} Gcmbcastcastrecorecomteleavequentent (intent); }   

    and looks like GcmBroadcastReceiver:

      The public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {@Override Public Zero onReceive (reference reference, intent) {ComponentName computer Application = new component name (context.getPackageName (), GcmIntentService.class.getName ()); startWakefulService (context, (intent.setComponent (COMP)); SetResultCode (Activity.RESULT_OK); }}    

    One very easy way to do this is to present the current task to the activity manager and Compare only the names of the squares:

      protected void onHandleIntent {intent of intent} {bundle extras = intent.getExtras (); ActivityManager am = (ActivityManager) this.getSystemService (ACTIVITY_SERVICE); // Get information from current active task list & lt; ActivityMazer RingtoneInfo & gt; TaskInfo = am.getRunningTasks (1); String Activity = name = taskInfo.get (0) .topActivity.getClassName (); If (activityName.equals (ActivityListView.class.getName ())) (/) run that particular method with ActivityListView ActivityListView.mymethod (additional); } Else {// Notification sending notification ("Receive:" + extras.toString ()); }}   

    In your AndroidManifest.xml you will need permission:

      & lt; Uses-permission Android: name = "Android.permission.GET_TASKS" />    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -