У меня есть foreground сервис и ongoind уведомление. На уведомлении есть кнопка, с помощью которой надо закрыть и сам сервис и уведомление. Закрывать уведомление и сервис по отдельности я уже понял как, но мне нужно всё вместе... Как это сделать?
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (intent.getAction().equals(Constants.ACTION.STARTFOREGROUND_ACTION)) {
Intent buttonIntent = new Intent(getApplicationContext(), ButtonReceiver.class);
buttonIntent.putExtra("notificationId", mId);
PendingIntent btPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, buttonIntent, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getBaseContext());
mBuilder.setSmallIcon(R.mipmap.icon)
.setContentTitle("someText")
.setContentText("someText")
.addAction(R.drawable.ic_close, "someText", btPendingIntent);
mBuilder.setPriority(2);
mBuilder.setOngoing(true);
Intent resultIntent = new Intent(this, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
// mId allows you to update the notification later on.
mNotificationManager.notify(mId, mBuilder.build());
} else if (intent.getAction().equals(
Constants.ACTION.STOPFOREGROUND_ACTION)) {
mNotificationManager.cancel(mId);
lm.removeUpdates(ll);
stopSelf();
}
return START_STICKY;
}
mNotificationManager.cancel(mId); stopSelf();
не прибивает сервис и уведомление?.. Суть вашей проблемы пока что не очень ясна – ЮрийСПб♦ 8 окт '16 в 21:19