Başka Fikir:
i f bir bildirimde bulunursanız normalde bir, iki veya 3 eylemine de ihtiyacınız vardır. Bir "NotifyManager" yarattım, ihtiyacım olan tüm bildirimleri oluşturuyor ve tüm Niyetli çağrıları alıyor. Bu yüzden tüm eylemleri yönetebilirim ve ayrıca işten çıkarma olayını tek bir yerde yakalayabilirim.
private PendingIntent createOnDismissedIntent(Context context) {
Intent intent = new Intent(context, NotifyPerformMailService.class).setAction("ACTION_NOTIFY_DELETED");
PendingIntent pendingIntent = PendingIntent.getService(context, SOME_NOTIFY_DELETED_ID, intent, 0);
return pendingIntent;
}
ve ben (NotificationManager olarak) böyle silme Niyet ayarlamak için kullanın OLDUĞUNU:
public class NotifyPerformService extends IntentService {
@Inject NotificationManager notificationManager;
public NotifyPerformService() {
super("NotifyService");
...//some Dagger stuff
}
@Override
public void onHandleIntent(Intent intent) {
notificationManager.performNotifyCall(intent);
}
deleteIntent (NotificationManager değil) bu kullanmak oluşturmak için
private NotificationCompat.Builder setNotificationStandardValues(Context context, long when){
String subText = "some string";
NotificationCompat.Builder builder = new NotificationCompat.Builder(context.getApplicationContext());
builder
.setLights(ContextUtils.getResourceColor(R.color.primary) , 1800, 3500) //Set the argb value that you would like the LED on the device to blink, as well as the rate
.setAutoCancel(true) //Setting this flag will make it so the notification is automatically canceled when the user clicks it in the panel.
.setWhen(when) //Set the time that the event occurred. Notifications in the panel are sorted by this time.
.setVibrate(new long[]{1000, 1000}) //Set the vibration pattern to use.
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
.setSmallIcon(R.drawable.ic_white_24dp)
.setGroup(NOTIFY_GROUP)
.setContentInfo(subText)
.setDeleteIntent(createOnDismissedIntent(context))
;
return builder;
}
ve son olarak aynı NotificationManager'da gerçekleştirme işlevi şöyledir:
public void performNotifyCall(Intent intent) {
String action = intent.getAction();
boolean success = false;
if(action.equals(ACTION_DELETE)) {
success = delete(...);
}
if(action.equals(ACTION_SHOW)) {
success = showDetails(...);
}
if(action.equals("ACTION_NOTIFY_DELETED")) {
success = true;
}
if(success == false){
return;
}
//some cleaning stuff
}
Works :) çok teşekkür ederim! –
Bu gecikti. Ben sadece bir kullanıcı bildirim tıklattığında ve iptal edildi, 'builder.setAutoCancel (true); olan bildirim için benzer bir yaklaşım olup olmadığını merak ettim, silme-Niyet –
@dev_android ödeme http:/tetiklenmiş değil /developer.android.com/reference/android/app/Notification.Builder.html#setContentIntent(android.app.PendingIntent) –