Mar*_*ies 3 notifications android
我如何应对通知解雇?当某个通知被取消时,我需要终止我的后台进程.
在这个帖子中,它说使用广播接收器,但是没有用于通知的intent-filter
如果您定义Intent手动触发您的类,则不需要使用intent-filter来获取广播.
只需实现BroadcastReceiver
public class NotificationDeleteReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// kill service here
}
}
Run Code Online (Sandbox Code Playgroud)
并将Receiver添加到AndroidManifest.xml
<receiver android:name="NotificationDeleteReceiver" />
Run Code Online (Sandbox Code Playgroud)
然后将PendingIndent设置为通知:
notification.deleteIntent = PendingIntent.getBroadcast(
this, 0, new Intent(context, NotificationDeleteReceiver.class), 0);
Run Code Online (Sandbox Code Playgroud)
这会奏效.
| 归档时间: |
|
| 查看次数: |
1433 次 |
| 最近记录: |