我正在尝试使用操作按钮创建一个android通知。我已经设置了一个开始一个活动,但我想另一个关闭通知,并没有把用户带到另一个屏幕/活动(没有采取我的应用程序的任何部分)Android:关闭通知的通知操作
我不想要使用'.auto cancel(true)',因为我想要保留通知,除非按下此操作按钮。
主要用途是针对正在进行的通知,因为它们不能用滑动删除。这个想法类似于“解雇”行动的android日历。
我正在尝试使用操作按钮创建一个android通知。我已经设置了一个开始一个活动,但我想另一个关闭通知,并没有把用户带到另一个屏幕/活动(没有采取我的应用程序的任何部分)Android:关闭通知的通知操作
我不想要使用'.auto cancel(true)',因为我想要保留通知,除非按下此操作按钮。
主要用途是针对正在进行的通知,因为它们不能用滑动删除。这个想法类似于“解雇”行动的android日历。
IMO使用一个BroadcastReceiver是取消通知一个更清洁的方式:
在AndroidManifest.xml:
<receiver
android:name=.NotificationCancelReceiver" >
<intent-filter android:priority="999" >
<action android:name="com.example.cancel" />
</intent-filter>
</receiver>
在Java文件
Intent cancel = new Intent("com.example.cancel");
PendingIntent cancelP = PendingIntent.getBroadcast(context, 0, cancel, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Action actions[] = new NotificationCompat.Action[1];
NotificationCancelReceiver:
public class NotificationCancelReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//Cancel your ongoing Notification
}
}
可以详细一点?你的目标是什么API级别?你应该能够通过豆豆+通知来做到这一切。 – cbrulak
我正在使用jellybean API - 我已经开始了一个活动,开始一个活动,购买我无法解决如何不开始一项活动。我可以使用广播接收器,但我不知道如果这可以让我清除通知。基本上我想通知行动清除自己(通知) – RiThBo