我得到Android應用程式,其接收推送消息在點擊後的推送通知的內容。訪問的推送消息(機器人)
如果用戶點擊推送消息,活動GoToNotification被調用。 這工作到目前爲止。
但我怎麼可以訪問推送消息的內容? Bundle.extra? 我想,對推送消息的部分內容作出反應,但捆綁額外總是空。
這裏我到目前爲止的代碼:
private void sendNotification(String msg, Bundle extras) {
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, GoToNotification.class), 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.icon)
.setContentTitle("Warning")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setAutoCancel(true)
.setWhen(System.currentTimeMillis())
.setExtras(extras)
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
public class GoToNotification extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = this.getIntent().getExtras();
if (extras != null) {
System.out.println(extras.toString());
} else {
System.out.println("extras is null");
}
}
}
在烏爾sendNotification的()方法ü應該添加烏爾數據捆綁。 –
pleae爲您提供GCM基地意向服務類的onMessage()方法的代碼 – warlock