Lan*_*nbo 32 android android-intent android-notifications
在我的中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)上,这根本不起作用.点击通知时没有任何反应.
我错过了这些放在一起的方式有什么变化吗?
mar*_*-hi 79
某些4.3设备似乎存在问题.可以通过为requestCode
参数提供非0值来解决此问题.
例:
PendingIntent.getActivity(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10778 次 |
最近记录: |