私のアプリケーションはサービスとして動作していますので、アプリケーションの実行中にユーザに通知する必要があります。通知バーに通知を追加しようとしています。それはサービスアプリケーションなので、私は常に通知を表示する必要があります。 アプリケーションを終了しても通知を削除できないようにするにはどうすればよいですか。 も、アプリケーションが終了した通知を表示する方法通知を削除しないようにする - Android
mBuilder.setOngoing(true);
、使用してスワイプでアプリケーションを削除するには、ユーザーを防ぐために私ができます。私は以下のコードを使用している
、
private void addNotificaiononNotificationBar(){
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("My notification")
.setContentText("Hello World!");
Intent resultIntent = new Intent(this, MainActivity.class);
// Because clicking the notification opens a new ("special") activity, there's
// no need to create an artificial back stack.
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
this,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
mBuilder.setOngoing(true);
// Sets an ID for the notification
int mNotificationId = 001;
// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(mNotificationId, mBuilder.build());
}
フォアグラウンドサービスを開始 –