2017-06-22 23 views
2

ドキュメントでは、context.startForegroundService(Intent)を使用してバックグラウンドでサービスを開始し、以前と同様にサービスでstartForegroundを呼び出して、アプリケーションの変更を加えました。Android Oがフォアグラウンドサービス通知を表示していない

NotificationCompat.Builder notification = new 
NotificationCompat.Builder(getApplicationContext()) 
      .setSmallIcon(R.mipmap.icon) 
      .setContentText("Content") 
      .setOngoing(true) 
      .setContentInfo("Info") 
      .setContentTitle("Title"); 
startForeground(1, notification.build()); 

これは正しくAndroidのNデバイス上のそれは、それは唯一の "バックグラウンドで実行されている新しいを表示する通知が表示されないのAndroid Oデバイスに通知を表示...バッテリーの詳細については、タップすると、データの使用 "

Android Oで正しく通知が表示されるようなものがありますか?

答えて

2

はい、NotificationCompatクラスのコンストラクタパラメータとしてチャネルを使用します。

+0

でnotficationを作成しますか? – Ryan

+0

あなたはベータサポートライブラリの新しいコンストラクタを意味しますか?残念ながら、外部の制約のためにベータライブラリを使用することはできません。私はライブラリの将来の証明をユーザーに提供しています。ライブラリをv26に移行するときにライブラリを更新する必要があります – Ryan

+0

はい、v26.0.0-beta2を使用してください – greywolf82

1

私の場合、上記の回答は機能しません。作業するためにチャネルを作成してから、チャネルIDを渡す必要があります。

NotificationManager notificationManager = 
     (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

String channelId = "some_channel_id"; 
CharSequence channelName = "Some Channel"; 
int importance = NotificationManager.IMPORTANCE_LOW; 
NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, importance); 
notificationManager.createNotificationChannel(notificationChannel); 

は、その後、あなたはこれで何を意味するかに展開することができ、同じcannelId

new NotificationCompat.Builder(this, channelId) 
関連する問題