Android 如何通过单击推送通知来了解应用程序是否已启动
我想知道是否有一个标志和参数可以告诉我用户是否通过单击通知栏中的推送通知来启动活动/应用程序 我在C2DMReceiver.java中的代码Android 如何通过单击推送通知来了解应用程序是否已启动,android,android-notifications,Android,Android Notifications,我想知道是否有一个标志和参数可以告诉我用户是否通过单击通知栏中的推送通知来启动活动/应用程序 我在C2DMReceiver.java中的代码 Context context = getApplicationContext(); PackageManager manager = context.getPackageManager(); Intent notificationIntent = manager .getLaunchInt
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的onCreate函数中的代码
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-bundle没有额外的内容。所以临时演员没有通过
那么还有别的办法吗??在iOS中,只需发布一个答案,就可以让访问此页面的用户获得解决方案 创建启动应用程序的意图时,需要使用
putExtra(ID\u-KEY,ID)
,在onCreate()方法中可以使用getIntent().getExtras().getInt(ID\u-KEY)
检索传递的id整数
传递的额外值可以是任何内容,如布尔值、字符串等
Source-当你的
接收者被呼叫时,只需向服务器发送一些信息:)谢谢Urban-尝试搜索各种格式的问题:)-这是有效的,除了Firebase推送“通知”消息,在点击通知之前不会调用应用程序。这意味着你不需要设置任何id。