Android: Ich versuche, eine Benachrichtigung aus der Benachrichtigungsleiste nach der Installation eines Pakets abzubrechen. Was ich tue, ist die folgende:NotificationManager.cancel (id) funktioniert nicht in einem Broadcast-Empfänger
public class MyBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "MyBroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
Uri data = intent.getData();
//some code goes here
//get the id of the notification to cancel in some way
notificationhelper._completeNotificationManager.cancel(id);
}
}
}
wo
public class notificationhelper {
public static NotificationManager _completeNotificationManager = null;
public void complete() {
if (_completeNotificationManager == null)
_completeNotificationManager = (NotificationManager) _context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(
R.drawable.notification,
_context.getString(R.string.notification),
System.currentTimeMillis());
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_NO_CLEAR;
_completeNotificationManager.notify(TEXT, id, notification);
}
}
Aber die notificationhelper._completeNotificationManager.cancel(id)
funktioniert nicht. Ich habe versucht, notificationhelper._completeNotificationManager.cancelAll();
zu verwenden, und es funktioniert. Was mache ich falsch?
Ich kratzte mich am selben Problem. stackoverflow.com/questions/38880330 Sparte meinen Tag. – mauron85
können Sie den vollständigen Code hochladen ich habe das gleiche Problem? –
ich eine Zufallszahl von 7 erzeuge eine Still Benachrichtigung Concel funktioniert nicht:/ –