Android KitKat中通知的未决意图(4.4.4)
我试图在用户点击通知时发送隐含的意图。这是我的代码:Android KitKat中通知的未决意图(4.4.4),android,android-4.4-kitkat,Android,Android 4.4 Kitkat,我试图在用户点击通知时发送隐含的意图。这是我的代码: // Intent used to share data Intent notificationIntent = new Intent(Intent.ACTION_SEND); notificationIntent.setType("text/plain"); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Intent used to share data
Intent notificationIntent = new Intent(Intent.ACTION_SEND);
notificationIntent.setType("text/plain");
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Intent message to share
String intentString = "I took " + stepsAlarm.getText() + " steps";
notificationIntent.putExtra(Intent.EXTRA_TEXT, intentString);
// Create a pending intent that triggers only when the notification is selected
PendingIntent contentIntent = PendingIntent.getService(context, 0, notificationIntent, 0);
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
//Resources res = context.getResources();
Notification.Builder builder = new Notification.Builder(context);
builder.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.small_not)
//.setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.ic_launcher))
.setTicker("Stepmeter")
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setContentTitle("Stepmeter Alert")
.setContentText("You took " + stepsAlarm.getText() + " steps");
Notification n = builder.build();
nm.notify(7, n);
通知显示得很好,但是当我选择它时,什么也没有发生。我还向清单添加了意图过滤器,如下所示:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="text/plain" />
</intent-filter>
我做错了什么?非常感谢。我认为你应该使用
pendingent.getBroadcast
而不是getService
,因为你没有启动服务。我认为你应该使用pendingent.getBroadcast
而不是getService
,因为你没有启动服务。使用pendingent.getActivity()
而不是getService()
。因为,您希望在单击通知时启动新活动 使用pendingent.getActivity()
而不是getService()
。因为,您希望在单击通知时启动新活动 谢谢,我将其更改为PendingEvent.getBroadcast,结果相同。谢谢,我将其更改为PendingEvent.getBroadcast,结果相同。