【发布时间】:2014-05-12 07:19:13
【问题描述】:
我正在开发一个在有传入事件时显示通知的应用程序。当用户点击通知时,他们将被带到应用程序中具有特定片段的活动。在装有 Android 4.1.2 的三星 Galaxy Note 2 上,此方法有效。但是,在搭载 Android 4.3 的三星 Galaxy S3 上,活动没有收到正确的操作,而是收到了意图“android.intent.action.MAIN”。
另外,S3 似乎也没有得到我想要的附加功能。 Note 2 接收良好。
通知代码如下:
Intent launchIntent;
String myType, myAction;
// myType and myAction are programmatically set
launchIntent = new Intent(context, MainActivity.class);
launchIntent.putExtra("Type", myType);
launchIntent.setAction(myAction);
PendingIntent pendingIntent = PendingIntent.getActivity(context, -1, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder noti = new NotificationCompat.Builder(
context).setContentTitle(context.getResources().getString(R.string.app_name))
setContentText(notificationMessage)
setSmallIcon(R.drawable.ic_stat_notify)
setContentIntent(pendingIntent)
setAutoCancel(true)
setWhen(System.currentTimeMillis())
setDefaults(Notification.DEFAULT_ALL);
notificationManager.notify(notifyId, noti.build());
有谁知道为什么它适用于一台设备而不是另一台设备?从 4.1 到 4.3 的意图是否有任何变化?
谢谢。
【问题讨论】:
-
你设置了
launchIntent.setAction(myAction);,但是你的myAction=null。什么是 myAction 值?为什么要手动设置? -
myAction 是以编程方式设置的,我使用它将信息传递给意图。在调用 PendingIntent.getActivity() 之前,我已经验证了该操作不是 null,而是设置值。
-
另外,S3 似乎也没有得到我想要的附加功能。 Note 2 接收良好。
-
解决设备特定问题非常困难。
-
看起来 S3 正在获得一个标准的启动 Intent,而不是您构建的那个。这就是为什么操作是错误的,并且缺少附加功能的原因。
标签: android android-intent notifications