本文介绍了在&QUOT回调;清除所有"按钮,在通知区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发和Android应用程序在那里我都数不过来的应用程序通过通知多少次启动。我的问题是,我不能赶上事件,用户presses清除按钮从通知区域。有什么办法或者为了知道何时清除按钮pressed?回调
I am developing and android app where i have to count how many times the app started through a notification. My problem is that i can't catch the event where the user presses "clear button" from the notification area. Is there any way or a callback in order to know when the clear button pressed?
我看了一下deleteIntent但我不知道如何使用它。
I have read about deleteIntent but i don't know how to use it.
感谢您提前
推荐答案
创建deleteIntent
Create a deleteIntent
Intent deleteIntent = new Intent(context, NotificationReceiver.class);
deleteIntent.setAction("delete");
它连接到您的通知
Attach it to your notification
notification.deleteIntent = PendingIntent.getBroadcast(context, 0, deleteIntent, 0);
创建一个新的类来拿起删除意图
Create a new class to pick up on the delete intent
public class NotificationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("TEST", "Clear app processing here");
}
}
添加到您的清单文件
Add to your manifest file
<receiver android:name=".NotificationReceiver"
android:enabled="true">
</receiver>
这篇关于在&QUOT回调;清除所有&QUOT;按钮,在通知区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!