如何从Android 8,9推送通知

时间:2019-07-13 13:38:33

标签: java android push-notification notifications

我尝试了所有代码,并尝试了google的官方代码,但是我的设备和模拟器上没有任何功能

我从YouTube和Google获得了很多代码,并且获得了许多博客,但也无济于事

//我尝试

     NotificationManager notificationManager
 = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);    
   Notification notification = new 
Notification.Builder(MainActivity.this)

       .setContentTitle("This is a Notification")
       .setContentText("Please pay Your Attention here..!")

      .setSmallIcon(R.drawable.ic_launcher_foreground)

      .setAutoCancel(true)

       .build();
      notificationManager.notify(CHANNEL_ID1,notification);
           }
                   });

//并尝试

  NotificationCompat.Builder builder = 
  new NotificationCompat.Builder(this, 
  CHANNEL_ID)

    .setSmallIcon(R.drawable.notification_icon)

    .setContentTitle(textTitle)

    .setContentText(textContent)

.setPriority(NotificationCompat.PRIORITY_DEFAULT);

//无济于事

代码应在Android 8和9上推送通知

如果能从android 4.4获得太多作品,那就更好了

1 个答案:

答案 0 :(得分:0)

在Android O中,必须在Notification Builder中使用频道

请查看此答案https://stackoverflow.com/a/43093261/8577615