在我的中Service,我使用以下代码在正常运行时打开通知:
private final static NOTIFICATION_ID = 412434;
private void startNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(
this);
builder.setSmallIcon(R.drawable.notification);
builder.setContentTitle("Running");
final Intent intent = new Intent(this, MainActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
final PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIntent);
builder.setOngoing(true);
builder.setAutoCancel(false);
notification = builder.build();
startForeground(NOTIFICATION_ID, notification);
}
Run Code Online (Sandbox Code Playgroud)
该PendingIntent是打开MainActivity时,通知被窃听.这在我的所有测试设备上运行得非常好,使用Android 2.3.3,2.3.5和Android 4.1.
它不起作用,但是在我的Nexus 7(Android 4.3)上,这根本不起作用.点击通知时没有任何反应.
我错过了这些放在一起的方式有什么变化吗?