2017-11-21 9 views
2

プロジェクトのapiターゲットを27に更新し、すべての通知を無効にしました。
API 26と27の通知の違いは何ですか?通知チャンネルIDとは何ですか?通知はAPIで機能しません27

 Notification notif = new NotificationCompat.Builder(this) 
       .setContentTitle(getString(R.string.app_name)) 
       .setContentText(message) 
       .setSmallIcon(R.mipmap.ic_launcher) 
       .setContentIntent(pIntent) 
       .setSound(alarmSound) 
       .setAutoCancel(true).build(); 
     notif.ledARGB = 0xFFff0000; 
     notif.flags = Notification.FLAG_SHOW_LIGHTS; 
     notif.ledOnMS = 100; 
     notif.ledOffMS = 100; 

     NotificationManager notificationCompatManager = 
       (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
     notificationCompatManager.notify(0, notif); 
+3

みんなええ、それをupvotedていますか?いいね。 –

+1

https://stackoverflow.com/questions/46990995/on-android-8-oreo-api-26-and-later-notification-does-not-display –

答えて

3

あなたは、API -27と27の両方に通知を表示するには、このメソッドを使用することができます:最初の分でこの質問を見た

void showNotification(String title, String content) { 
    NotificationManager mNotificationManager = 
      (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { 
     NotificationChannel channel = new NotificationChannel("default", 
       "YOUR_CHANNEL_NAME", 
       NotificationManager.IMPORTANCE_DEFAULT); 
     channel.setDescription("YOUR_NOTIFICATION_CHANNEL_DISCRIPTION"); 
     mNotificationManager.createNotificationChannel(channel); 
    } 
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext(), "default") 
      .setSmallIcon(R.mipmap.ic_launcher) // notification icon 
      .setContentTitle(title) // title for notification 
      .setContentText(content)// message for notification 
      .setSound(alarmSound) // set alarm sound for notification 
      .setAutoCancel(true); // clear notification after click 
    Intent intent = new Intent(getApplicationContext(), MainActivity_.class); 
    PendingIntent pi = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 
    mBuilder.setContentIntent(pi); 
    mNotificationManager.notify(0, mBuilder.build()); 
} 
+0

チャンネルIDは何ですか?詳細をお送りください –

+0

この記事をご覧くださいhttps://medium.com/exploring-android/exploring-android-o-notification-channels-94cd274f604c –

+0

ありがとうございます。通知を管理するライブラリはありますか? (インテグレーションを確認してください) –

関連する問題