我想知道是否有標誌和參數可以告訴我用戶是否通過點擊通知欄中的推送通知來啓動活動/應用程序。如何通過點擊推送通知來啓動應用程序
我在C2DMReceiver.java
代碼Context context = getApplicationContext();
PackageManager manager = context.getPackageManager();
Intent notificationIntent = manager
.getLaunchIntentForPackage(packageName);
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
**notificationIntent.putExtra("fromRemote", true);**
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification();
notification.icon = R.drawable.icon;
notification.tickerText = message;
notification.number = badge;
notification.when = System.currentTimeMillis();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults = Notification.DEFAULT_ALL;
notification.setLatestEventInfo(context, "Draw Something", message,
pendingIntent);
notification.contentIntent = pendingIntent;
notificationManager.notify(0, notification);
我試着設置
notificationIntent.putExtra("fromRemote", true);
,但應用程序推出的時候有在意向無需額外。
我在我的mainactivity
Bundle extras = getIntent().getExtras();
if (extras != null) {
print("onCreate - bundle has extras");
for (String key: extras.keySet())
{
Log.v ("mytag", "MainActivity onCreate key =" + key);
}
}
else {
Log.v ("mytag", "onCreate - bundle has NO extras");
}
輸出我得到的OnCreate函數代碼的onCreate - 束具有無需額外。所以臨時演員沒有得到通過。
那麼還有其他方法嗎?這很容易在iOS
僅發佈一些東西到服務器時,你的'Receiver'得到所謂:) – Sadegh
http://stackoverflow.com/questions/1198558/how-to-send-parameters-from-a-notification-click-to-an-activity – Urban
感謝Urban - 嘗試搜索各種格式的問題:) - 它的工作原理 – Anand