English 中文(简体)
Android 4: 无法通过擦拭来驳回通知 :
原标题:Android 4: can t dismiss notification by swiping
  • 时间:2012-05-23 10:46:27
  •  标签:
  • android

我有一些代码 创建一些通知, 这是非常基本的。

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

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.

问题回答

你无法删除你的通知, 因为它是在一个"未定"的国家。

<强> 首先解决问题:

用以下代码取代设置标记 :

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

默认值为默认区划, 标记区划的标记值为默认区划 。

“强”和“强”是为什么它还在持续?“/强”

您可能已经知道通知的旗帜( 和默认) 是由 < a href=" http:// en.wikipedia. org/ wiki/ Bitwise_ Operation > > bittwise operation 设置的。 表示每面旗帜的常值是 2 的功率 。 添加这些旗帜后, 将产生一套旗帜的独特编号, 从而能够真正快速地计算实际设置的旗帜 。

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

您应该使用 setOnway(bolean 进行中)

Set whether this is an "ongoing" notification. Ongoing notifications cannot be dismissed by the user, so your application or service must take care of canceling them. They are typically used to indicate a background task that the user is actively engaged with (e.g., playing music) or is pending in some way and therefore occupying the device (e.g., a file download, sync operation, active network connection).

您可以使用

.setOngoing(false);

只需插入此行, 当您发出通知...

// Will show lights and make the notification disappear when the presses it
notification.flags == Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签