android 状态栏通知消息

Posted 英文不好太难了

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android 状态栏通知消息相关的知识,希望对你有一定的参考价值。

android如何通知消息

onCreate()方法里添加
// 状态栏用
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) 
     String channelId = "chat";
     String channelName = "通知消息";
     int importance = NotificationManager.IMPORTANCE_HIGH;
      createNotificationChannel(channelId, channelName, importance);
  
  //调用要通知的消息
  showNotification();
    private void showNotification() 
        Intent intentMain = new Intent(this, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intentMain, 0);
        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        Notification notification = new NotificationCompat.Builder(this, "chat")
                .setContentTitle("运行中")
                .setContentText("运行中...")//内容
                .setWhen(System.currentTimeMillis())
                .setContentIntent(pendingIntent)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                .setAutoCancel(false)
                .build();
        manager.notify(1, notification);
    
 //消息通道,状态栏用
  @TargetApi(Build.VERSION_CODES.O)
 private void createNotificationChannel(String channelId, String channelName, int importance) 
 NotificationChannel channel = new NotificationChannel(channelId, channelName, importance);
 NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(channel);
 

以上是关于android 状态栏通知消息的主要内容,如果未能解决你的问题,请参考以下文章

android 状态栏通知消息

android 状态栏通知消息

Android解析推送通知不会在状态栏上显示消息

android phonegap 通知状态栏显示啥

android:Notification实现状态栏的通知

Android自定义状态栏通知(Status Notification)的正确实现