0
我有 一個gcm服務接收器,完成了書。 這裏的主要部分Android意圖 - >活動交互
//Magick. Create Intent that will show alert.
mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
Intent ma = new Intent(this, Home.class);
Bundle b = ma.getExtras();
if (b != null && b.containsKey("Alert_call"))
{ma.removeExtra("Alert_call");}
if (b != null && b.containsKey("Alert_poi"))
{ma.removeExtra("Alert_poi");}
ma.putExtra("Alert_call", true);
ma.putExtra("Alert_poi", msg);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,ma, 0);
//Make the notification itself.
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(p.GetAlertIconFromType())
.setContentTitle(p.GetAlertHeaderFromType())
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(p.coordsAdress + "\n" + p.ShortDesc))
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))//Do the ring
.setDefaults(Notification.DEFAULT_VIBRATE)//Do the vibe
.setDefaults(Notification.DEFAULT_LIGHTS)//Do the Lights blink
.setContentText(p.coordsAdress + "\n" + p.ShortDesc);
//Send.
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
現在,在活動方面我趕上這種意圖的包,看看我是否有這些「Alert_call」 PARAMS。如果是這樣 - 使用這些ti顯示一些特定的信息。
//Magick. Create Intent that will show alert.
mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
Intent ma = new Intent(this, Home.class);
Bundle b = ma.getExtras();
if (b != null && b.containsKey("Alert_call"))
{ma.removeExtra("Alert_call");}
if (b != null && b.containsKey("Alert_poi"))
{ma.removeExtra("Alert_poi");}
ma.putExtra("Alert_call", true);
ma.putExtra("Alert_poi", msg);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,ma, 0);
//Make the notification itself.
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(p.GetAlertIconFromType())
.setContentTitle(p.GetAlertHeaderFromType())
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(p.coordsAdress + "\n" + p.ShortDesc))
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))//Do the ring
.setDefaults(Notification.DEFAULT_VIBRATE)//Do the vibe
.setDefaults(Notification.DEFAULT_LIGHTS)//Do the Lights blink
.setContentText(p.coordsAdress + "\n" + p.ShortDesc);
//Send.
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
- > DisplayView部分
//Magick. Create Intent that will show alert.
mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
Intent ma = new Intent(this, Home.class);
Bundle b = ma.getExtras();
if (b != null && b.containsKey("Alert_call"))
{ma.removeExtra("Alert_call");}
if (b != null && b.containsKey("Alert_poi"))
{ma.removeExtra("Alert_poi");}
ma.putExtra("Alert_call", true);
ma.putExtra("Alert_poi", msg);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,ma, 0);
//Make the notification itself.
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(p.GetAlertIconFromType())
.setContentTitle(p.GetAlertHeaderFromType())
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(p.coordsAdress + "\n" + p.ShortDesc))
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))//Do the ring
.setDefaults(Notification.DEFAULT_VIBRATE)//Do the vibe
.setDefaults(Notification.DEFAULT_LIGHTS)//Do the Lights blink
.setContentText(p.coordsAdress + "\n" + p.ShortDesc);
//Send.
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
現在,我面臨的問題是這樣的:
如果我從這個警報啓動活動 - 一切正常。 但是,如果我有這個活動allready打開(例如睡着),我推這個警報 - 我接受null作爲參數在INtent,或舊的(用於啓動活動)。
所以,問題:
它看起來像我需要得到這個運行的活動意圖,並且在其添加新的數據時,我推警報。
這是正確的嗎?如果是這樣 - 範你請引導我在哪裏閱讀關於它?