0

I am developing small android application in which I want to integrate GCM. I used one module for it and its working fine. The only problem with it is when my application is open and if I click on notification it relaunch my application which I don't want.. What I want if application is already running then just show running window and if application is closed then launch application... In my module code for onmessage received looks like

int icon = 0x7f020000;

    CharSequence tickerText = new String("app anme: " + hashdata.get("messages"));
    long when = System.currentTimeMillis();

    CharSequence contentTitle = "app name";
    CharSequence contentText = new String(" " + hashdata.get("messages"));

    Intent notificationIntent = new Intent(this, GCMIntentService.class);

    Intent launcherintent = new Intent("android.intent.action.MAIN");
    launcherintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

    launcherintent.setComponent(ComponentName.unflattenFromString("com.example/com.example.ExampleActivity"));
    launcherintent.addCategory("android.intent.category.LAUNCHER");

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, launcherintent, 0);

    Notification notification = new Notification(icon, tickerText, when);

    notification.defaults = Notification.DEFAULT_ALL;
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    notification.setLatestEventInfo(context, contentTitle, contentText,contentIntent);
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
    mNotificationManager.notify(1, notification);

My module is working fine if application is closed.. But relaunch application which is already running which is not expected...... Need Help..... Thank you...........

4

1 回答 1

1

对于 Gcm 实现,这是最好的教程,也可能对您有用。 适用于 Android 的 Google Cloud Messaging (GCM) 简单教程

于 2012-09-18T07:18:30.157 回答