PendingIntent没有Android的4.3开放活动 [英] PendingIntent not opening Activity in Android 4.3

查看:172
本文介绍了PendingIntent没有Android的4.3开放活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的服务,我打开了对正常运行的通知,使用这个code:

In my Service, I open up a notification on normal run, using this code:

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);
}

PendingIntent 是打开 MainActivity 时,通知被窃听。这工作完全正常对我所有的测试设备,采用Android 2.3.3,2.3.5和Android 4.1。

The PendingIntent is to open the MainActivity when the Notification is tapped. This works perfectly fine on all my test devices, using Android 2.3.3, 2.3.5 and Android 4.1.

但是,它没有在我的Nexus 7(安卓4.3),这并不能在所有工作。当我点击的通知,没有任何反应。

It does not work, however on my Nexus 7 (Android 4.3), this doesn't work at all. Nothing happens when I tap on the Notification.

做了一些改变的方式,这些都放在一起,我错过了?

Did something change in the way these are put together that I missed?

推荐答案

似乎有一些4.3的设备的问题。它可以通过提供一个非0值到请求code 参数来解决。

There seems to be an issue on some 4.3 devices. It can be resolved by providing a non 0 value to the requestCode parameter.

例如:

PendingIntent.getActivity(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);

这篇关于PendingIntent没有Android的4.3开放活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆