我正通過PendingIntent從GCMIntentService發送一個意向。我在intent中插入一些字符串,並在PendingIntent中調用一個將接收意圖的活動。但數據不是我發送的。這是截圖。 意圖未正確投遞
示出的第一意圖就是我發送,並且所述第二就是我接收。這裏是發送代碼:
Intent intent = new Intent(getBaseContext(),
Group_Chat_MainActivity.class);
intent.putExtra("group_id", group_id);
intent.putExtra("group_title", name);
intent.putExtra("from_push", true);
PendingIntent pendingIntent = PendingIntent.getActivity(
getBaseContext(), 100,
intent, 0);
Notification notification = new NotificationCompat.Builder(
getBaseContext()).setContentTitle("Paisa Swipe")
.setContentText(msg)
.setSmallIcon(R.drawable.home_logo)
.setTicker(ticker)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setContentIntent(pendingIntent)
.setAutoCancel(true).build();
notificationManager.notify(Integer.parseInt(group_id),
notification);
當我點擊通知,它發送到Group_Chat_MainActivity類。在這方面,我使用getIntent()來獲取意向數據:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chat_activity_main);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getIntent().getStringExtra("group_title")
getIntent().getStringExtra("group_id")
getIntent().getBooleanExtra("from_push",false)
}
在這裏我得到我送那麼什麼不同的字符串。有任何想法嗎?
你確定你的'getBaseContext()'不爲空?這段代碼是在一個片段? – 2014-11-24 13:36:49
其中一個你得到錯誤的值 – 2014-11-24 13:37:59
@NoName group_title它正在返回奇怪的值「test group」。我搜索了我的整個項目,即使在代碼或xmls中也沒有名爲「test」的字符串:P – Prince 2014-11-24 13:39:01