安卓4.0:无法通过滑动关闭通知 [英] Android 4: can't dismiss notification by swiping

查看:223
本文介绍了安卓4.0:无法通过滑动关闭通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些code,创造了一些通知,这是很基本的。

I have some code that creates some notifications, it's really basic.

int icon = R.drawable.notification;
CharSequence tickerText = "Text";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);

Context context = getApplicationContext();
CharSequence contentTitle = "Text";
CharSequence contentText = "Text";
Intent notificationIntent = new Intent(this, RequestActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notification.flags |= Notification.DEFAULT_SOUND;
notification.flags |= Notification.DEFAULT_VIBRATE;
notification.flags |= Notification.DEFAULT_LIGHTS;
notification.flags |= Notification.FLAG_AUTO_CANCEL;

mNotificationManager.notify(notificationID, notification);

这一切都工作在2.1罚款。
在4.0中,这一切工作正常,除了刷卡到解雇行动不起作用。通知稍微转到一边,然后坚持和反弹。
任何想法?
谢谢你。

It all works fine in 2.1. In 4.0, it all works fine except the swipe-to-dismiss action doesn't work. The notification goes slightly to the side then sticks and bounces back. Any idea? Thanks.

推荐答案

您不能刷卡走你的通知,因为它是在一个正在进行的-State。

You can't swipe away your notification, because it is in an "ONGOING"-State.

第一个解决方案:

替换以下code设置标志:

Replace setting flags with following code:

notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.flags |= Notification.FLAG_AUTO_CANCEL;

默认设置是默认节,对于旗节标志。

Defaults are for the defaults-section, flags for the flags-section.

现在为什么它正在进行的原因是什么?

正如你可能已经知道标志(和默认值)的通知是由位操作设定。装置,每个标志有一个恒定值,它是2的幂添加他们导致一个唯一的数字为一组标志,这使得它真正的快速计算哪些标志实际设置

As you might already know flags (and defaults) for notifications are set by a bitwise operation. Means each flag has a constant value which is a power of 2. Adding them results in an unique number for a set of flags which makes it real fast to calculate which flags are actually set.

<一个href=\"http://developer.android.com/reference/android/app/Notification.html#DEFAULT_VIBRATE\">Notification.DEFAULT_VIBRATE和<一个href=\"http://developer.android.com/reference/android/app/Notification.html#FLAG_ONGOING_EVENT\">Notification.FLAG_ONGOING_EVENT
2 相同contant值。

Notification.DEFAULT_VIBRATE and Notification.FLAG_ONGOING_EVENT have the same contant value of 2.

这篇关于安卓4.0:无法通过滑动关闭通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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