Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
181 views
in Technique[技术] by (71.8m points)

android - Remove notification from notification bar from other applications

I want to remove notifications from another application shown in the notification bar. Is that possible? NotificationManager.cancelAll(); cancels only notifications shown by the calling application, as far as I know.

Why do I want to do this?

I have an application that reads and sends SMS via a webpage, and I want this application to co-exits with existing SMS applications like Handcent SMS. The way I want it to work is that when reading newly received SMS via the webpage, I want to cancel the new SMS notification shown by Handcent SMS because the new SMS is now read. I'm marking the SMS as read, and Handcent SMS recognize it as read once i open up Handcent SMS, but the notification is still there until i click on the actual SMS.

There are two senarios; number 1:

  1. The android device receives a SMS.
  2. A notification is shown by Handcent SMS.
  3. The user reads the SMS on the device.
  4. Handcent SMS removes the notification and marks the SMS as read.

Senario 2:

  1. The android device receives a SMS.
  2. A notification is shown by Handcent SMS.
  3. The user reads the SMS via the web interface.
  4. My application clear the new SMS notification shown by Handcent SMS and marks the SMS as read.

Is this possible?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From Android 4.3 onward, you can now cancel notifications from any apps.

You need to register your app as NotificationListenerService, then call NotificationListenerService.cancelNotification(String pkg, String tag, int id) to cancel one notification.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...