GVKun编程网logo

Android中通过Notification&NotificationManager实现消息通知(android获取通知)

4

在本文中,我们将给您介绍关于Android中通过Notification&NotificationManager实现消息通知的详细内容,并且为您解答android获取通知的相关问题,此外,我们还将为您

在本文中,我们将给您介绍关于Android中通过Notification&NotificationManager实现消息通知的详细内容,并且为您解答android获取通知的相关问题,此外,我们还将为您提供关于Android Notification 消息通知 相关资料.md、android Notification 的一个简单应用(在 Notification 中嵌入一个进度条,并且这个 Notification 点击消失但不会跳转)、Android Notification 详解 —— 响应 notification 事件、Android NotificationCompat通知消息的知识。

本文目录一览:

Android中通过Notification&NotificationManager实现消息通知(android获取通知)

Android中通过Notification&NotificationManager实现消息通知(android获取通知)

notification是一种让你的应用程序在没有开启情况下或在后台运行警示用户。它是看不见的程序组件(broadcast Receiver,Service和不活跃的Activity)警示用户有需要注意的事件发生的最好途径。

  1、新建一个android项目

    我新建项目的 minSdkVersion="11",targetSdkVersion="19"。也就是支持最低版本的3.0的。

  2、习惯性地打开项目清单文件AndroidManifest.xml,添加一个权限:<uses-permission android:name="android.permission.VIBRATE"/> 不添加不行的。

  3、在布局activity_main.xml中添加几个按钮,样子就大概这样,垂直排版的LinearLayout

具体代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  android:orientation="vertical"
  tools:context=".MainActivity" >
    <Button 
      android:id="@+id/btn_01"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="3.0以前版本的notification,用新的吧"
      android:onClick="click"
      />
    <Button 
      android:id="@+id/btn_02"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="大视图文本通知"
      android:onClick="click"
      />
    <Button 
      android:id="@+id/btn_03"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="大视图图片通知"
      android:onClick="click"
      />
    <Button 
      android:id="@+id/btn_04"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="进度条通知"
      android:onClick="click"
      />
</LinearLayout>@H_301_20@

   

4、MainActivity中的代码:

 package com.xin.day__notificationdemo;
  import java.util.Timer;
  import java.util.TimerTask;
  import android.app.Activity;
  import android.app.Notification;
  import android.app.notificationmanager;
  import android.app.PendingIntent;
 import android.content.Intent;
 import android.graphics.BitmapFactory;
 import android.os.Bundle;
 import android.support.v.app.NotificationCompat;
 import android.support.v.app.NotificationCompat.BigPictureStyle;
 import android.support.v.app.NotificationCompat.BigTextStyle;
 import android.support.v.app.NotificationCompat.Builder;
 import android.util.Log;
 import android.view.View;
 public class MainActivity extends Activity {
   //通知的唯一标识,在一个应用程序中不同的通知要区别开来
   private static final int NO = x;
   private static final int NO = x;
   private static final int NO = x;
   private static final int NO = x;
   //进度条要用
   private int progress = ;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);
   }
   //click方法,和xml文件中的各个按钮的onClick属性的值要一致
   public void click(View view) {
     //创建notificationmanager
     final notificationmanager manager = (notificationmanager) getSystemService(NOTIFICATION_SERVICE);
     //用switch语句控制四个控件
     switch (view.getId()) {
     case R.id.btn_: {
       Notification notification = new Notification();
       notification.icon = R.drawable.ic_launcher;
       notification.tickerText = "有消息了。。。";
       Intent intent = new Intent(this,MainActivity.class);
       PendingIntent pendingIntent = PendingIntent.getActivity(this,intent,PendingIntent.FLAG_UPDATE_CURRENT);
       notification.setLatestEventInfo(this,".以前的通知","试试而已",pendingIntent);
       notification.when = System.currentTimeMillis();
       notification.defaults = Notification.DEFAULT_ALL;
       notification.flags = Notification.FLAG_AUTO_CANCEL;
       notification.number = ;
       notification.vibrate = new long[]{,};
       manager.notify(NO,notification);
     }
     break;
     case R.id.btn_:{
       //大视图文本通知
       //创建消息构造器,在扩展包
       NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
       //设置当有消息是的提示,图标和提示文字
       builder.setSmallIcon(R.drawable.ic_launcher).setTicker("有新消息了");
       //需要样式
       BigTextStyle style = new BigTextStyle();
       style.setBigContentTitle("上课通知");//通知的标题
       style.bigText("今天下午要在综B上jsp");//通知的文本内容
       //大视图文本具体内容
       style.setSummaryText("这是正常的课程安排,请各位同学按时上课");
       builder.setStyle(style);
       //显示消息到达的时间,这里设置当前时间
       builder.setWhen(System.currentTimeMillis());
       //获取一个通知对象
       Notification notification = builder.build();
       notification.flags = Notification.FLAG_AUTO_CANCEL;
       //发送(显示)通知
       //notify()第一个参数id An identifier for this notification unique within your application
       //get?意思说,这个通知在你的应用程序中唯一的标识符
       manager.notify(NO,notification);
     }
     break;
     case R.id.btn_:{
       //大视图图片通知
       NotificationCompat.Builder builderPic = new Builder(this);
       builderPic.setSmallIcon(R.drawable.ic_launcher).setTicker("新浪体育提醒");
       //进行设置
       BigPictureStyle pictureStyle = new BigPictureStyle();
       pictureStyle.setBigContentTitle("新浪体育 快船VS骑士 ");
       pictureStyle.bigPicture(BitmapFactory.decodeResource(getResources(),R.drawable.ic_game));
       pictureStyle.setSummaryText(" 快船VS骑士 天王山之战!!!");//不要在意文字
       //设置样式
       builderPic.setStyle(pictureStyle);
       //设置显示的时间
       builderPic.setWhen(System.currentTimeMillis());
       Notification notification = pictureStyle.build();
       notification.flags = Notification.FLAG_AUTO_CANCEL;
       //
       manager.notify(NO,notification);
     }
     break;
     case R.id.btn_:{
       //进度条通知
       final NotificationCompat.Builder builderProgress = new NotificationCompat.Builder(this);
       builderProgress.setSmallIcon(R.drawable.ic_launcher).setTicker("进度条通知");
       builderProgress.setProgress(,progress,false);
       final Notification notification = builderProgress.build();
       //发送一个通知
       manager.notify(NO,notification);
       //创建一个计时器
       Timer timer = new Timer();
       timer.schedule(new TimerTask(){
         @Override
         public void run() {
           Log.i("progress",progress+"");
           while(progress <= ){
             progress ++;
             try {
               Thread.sleep();
             } catch (InterruptedException e) {
               // Todo Auto-generated catch block
               e.printstacktrace();
             }
             //更新进度条
             builderProgress.setProgress(,false);
             //再次通知
             manager.notify(NO,builderProgress.build());
           }
           //计时器退出
           this.cancel();
           //进度条退出
           manager.cancel(NO);
           return;//结束方法
         }
       },);
     }
     break;
     default:
       break;
     }
   }
 }@H_301_20@

5、运行:我的虚拟机版本是4.0的(api19),按住通知左(右)滑动就可以让通知小时了。

效果如下:


Android Notification 消息通知 相关资料.md

Android Notification 消息通知 相关资料.md

[TOC]

Android Notification 消息通知 相关资料

Android 5.0 Lollipop (API 21)无法正常显示通知图标,只能看到一个白色方块或灰色方块的问题

解决方案

详情见参考资料2.

  1. 使用在线PS 去掉原来图标的背景色,保留主题图标为白色 Photopea | Online Photo Editor
  2. 打开 Android Asset Studio Notification icon generator 然后上传新LOGO
  3. 下载 处理好后的新图标即可. android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? R.mipmap.ic_launcher_white : R.mipmap.ic_launcher

参考资料

  1. Android 5.0 行为变更 | Android Developers

    在白色(或非常浅)的背景上使用深色文本绘制通知,以便与新的 Material Design 小部件匹配。请确保您的所有通知都与新的配色方案协调一致。如果您的通知看上去不协调,请进行修正:

    • 使用 setColor() 在您的图标图像后面的圆形中设置重点色彩。
    • 更新或移除使用色彩的资源。系统在操作图标和主要通知图标中忽略所有非阿尔法通道。您应假设这些图标仅支持阿尔法通道。系统用白色绘制通知图标,用深灰色绘制操作图标。
  2. Android Push Notifications: Icon not displaying in notification, white square shown instead - Stack Overflow

    • For 5.0 Lollipop "Notification icons must be entirely white".
    Notification notification = new NotificationCompat.Builder(this);
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        notification.setSmallIcon(R.drawable.icon_transperent);
       notification.setColor(getResources().getColor(R.color.notification_color));
    } else {
        notification.setSmallIcon(R.drawable.icon);
    }
    
    • I found a link where we can generate our own white icon, try this link to generate white icon of your launcher icon. Open this Link Android Asset Studio and upload your ic_launcher or notification icon
  3. android 5.0以上通知栏、状态栏图标变成白色 - 晕菜一员 - 博客园

    因为google在android5.0上面做了限制,为了统一系统风格。之后的状态栏icon就不能够随便用一张色彩丰富的图片了,只能够有白色和透明两个颜色出现。

    5.0以上(不包含5.0),系统默认通知栏图标为系统启动图标,会自动将通知栏的图标(有色区域)全部填充为白色,

  4. Android 的 notification 图标问题 - V2EX

    因为原先的那种形式的图标不好看, 颜色太花, 在状态栏上一点也不好看. 并且这也是 Material Design 的规范了 ( https://www.google.com/design/spec/patterns/notifications.html) 实际上这样的改变在 Android 5.0 里好看了很多, 如果你看到有些厂商还不知道的, 那么就是他们菜或者是上班混日子.

Android 8.0 Oreo(API 26) 及更高版本 如何更新 消息通知渠道 设置的问题

解决方案:无!

谷歌官方文档说明了,一旦渠道创建完毕,那么最终管理权利就移交给用户了. 程序最多可以将其删除, 想修改是不可能的了.

ByYe:间接解决方案=根据title或者sound的不同,创建不同的渠道.来间接实现.

问题详情

想重用一个渠道, 只是修改不同的部分,比如提示声音铃声不同.

参考资料

  1. https://developer.android.com/guide/topics/ui/notifiers/notifications#limits

    发布限制 从 Android 8.1(API 级别 27)开始,应用无法每秒发出一次以上的通知提示音。如果应用在一秒内发出了多条通知,这些通知都会按预期显示,但是每秒中只有第一条通知发出提示音。

    不过,Android 还对通知更新频率设定了限制。如果您过于频繁地发布有关某条通知的更新(不到一秒内发布多个),系统可能会放弃部分更新。

  2. How to properly update notification channel android oreo - Stack Overflow

    Once a notification channel is created, the user has ultimate control over it''s settings.

    As the developer, you can only change the channel''s title and description.

    If you want to recreate the channel, you have to use a different id.

    See: https://developer.android.com/training/notify-user/channels

  3. Create and Manage Notification Channels | Android Developers

    • Starting in Android 8.0 (API level 26), all notifications must be assigned to a channel
    • After you create a notification channel, you cannot change the notification behaviors—the user has complete control at that point. Though you can still change a channel''s name and description.
    • But remember that once you create the channel, you cannot change these settings and the user has final control of whether these behaviors are active.
  4. Android Oreo 通知新特性,这坑老夫先踩了 - 简书

    其中“lockscreenVisibility”和“setBypassDnd”是无法生效的,因为从源码中来看,

    只能被系统或排序服务(Android Notification Ranking Service)更改。

Android 7.0 Nougat(API 24) 及更高版本 消息通知 设置的自定义铃声 无法正常播放问题

解决方案

  1. 详情参见 参考资料1
  2. 采用的是使用自定义ContentProvider The Axe: Use a Custom ContentProvider
  3. 实际测试效果: Android 8.1 + Android 4.4.4 版本都正常.

解决步骤:

  1. 下载最新版本的cwac-provider-0.5.3.jar并集成到项目中

    GitHub - commonsguy/cwac-provider: CWAC-Provider: Helping to Make Content Providers Sane

  2. 按文档要求在清单文件里AndroidManifest.xml添加了以下代码:

    <provider
              android:name="com.commonsware.cwac.provider.StreamProvider"
              android:authorities="${applicationId}.DataFilesSoundsStreamProvider"
              android:exported="true">
        <meta-data
                   android:name="com.commonsware.cwac.provider.STREAM_PROVIDER_PATHS"
                   android:resource="@xml/data_files_sounds_paths" />
    </provider>
    
  3. 在项目资源目录里添加了res/xml/data_files_sounds_paths.xml文件

    <?xml version="1.0" encoding="utf-8"?>
    <paths>
        <files-path
                name="data_files_sounds"
                path="sounds"
                readOnly="true" />
    </paths>
    
  4. 将代码中原使用Uri.fromFile(file)的地方替换为com.commonsware.cwac.provider.StreamProvider.getUriForFile(mContext.getPackageName() + ".DataFilesSoundsStreamProvider", file)即可

问题详情

问题还原步骤:

  1. 使用 NotificationCompat.Builder.setSound 设置自定义铃声
  2. 自定义铃声 位于 SDCard外置存储卡Environment.getExternalStorageDirectory() 某个目录里.

结果:

  1. Android 6 之前的版本 正常 播放.

  2. Android 7 以后的版本 无法 播放.

    抛出异常:StrictMode: file:// Uri exposed through Notification.sound

参考资料

  1. java - Android 7.0 Notification Sound from File Provider Uri not playing - Stack Overflow

    If you were using file: Uri values, they no longer work on Android 7.0 if your targetSdkVersionis 24 or higher, as the sound Uri is checked for compliance with the ban on file: Uri values. 假如你还在使用file:uri形式的路径值, 那么Android 7.0以后的版本就不再支持了(只要targetSdkVersion > 24)

    However, if you try a content: Uri from, say, FileProvider, your sound will not be played... because Android does not have read access to that content.

    但是,假如你尝试使用content: 开头的Uri对象,例如通过FileProvider可以拿到这类对象,结果你的自定义通知铃声还是不能正常播放囧。原因是Android系统本身没有你指定的文件的读取权限

    解决方案有:

    1. 使用grantUriPermissions()授权,让其具有读取权限The Scalpel: grantUriPermissions()

      grantUriPermission("com.android.systemui", soundUri,Intent.FLAG_GRANT_READ_URI_PERMISSION); 缺点: 在于你不知道给授权,Android默认会是com.android.systemui,至于其它厂商的系统是不是这个,就很难说了.

      Thanks a lot for the thorough answer. To verify the robustness of the grantUriPermission solution (''The Scalpel''), I''ve tested it in different physical devices (including LG, Motorola, HTC, Samsung and Sony), from API 15 up to API 24. It works correctly on all of them, so the solution seems pretty solid (although certainly hacky). – jmart Sep 7 ''16 at 18:24

    2. 不提供完全自定义的铃声,仅仅提供部分可选择的铃声 The Guillotine: No More User Files

      原因是:android.resource开头的Uri对象路径Android系统默认是支持直接读取的,所以只要将部分可供选择的铃声放在APP的RAW资源目录里即可.

      缺点:在于让用户无法完全自定义自己的铃声了,可能你的用户不一定会买账.

    3. 使用自定义ContentProvider The Axe: Use a Custom ContentProvider

      FileProvider 不能直接用,因为一旦设置成 exported 那么一启动APP就会崩溃.

      那么可用的方案就是自定义一个支持exported且具有读取权限的 ContentProvider了.

      可以参见: GitHub - commonsguy/cwac-provider: CWAC-Provider: Helping to Make Content Providers Sane

      Using a read-only ContentProvider (see "The Axe") is the better answer. I''ll probably rig up my StreamProvider such that if you mark it as exported, it treats everything as read-only, which would handle this problem fairly cleanly. – CommonsWare

android Notification 的一个简单应用(在 Notification 中嵌入一个进度条,并且这个 Notification 点击消失但不会跳转)

android Notification 的一个简单应用(在 Notification 中嵌入一个进度条,并且这个 Notification 点击消失但不会跳转)

   网上很多的例子都是直接获取 Notification 对象来设置一个通知,其实 Notification 跟 Dialog 一样,也有自己的 Builder,可以用 builder 对象来设置一个 Notification

    这个例子是在 Notification 中嵌入一个进度条,并且这个 Notification 点击消失但不会跳转(跟 android 的 vcard 文件导入时弹出的 Notification 一样)

    NotificationManager mNotificationManager = (NotificationManager)
                context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification.Builder builder = new Notification.Builder(context);
        builder.setOngoing(true);
        builder.setProgress (total, current, false);// 设置进度条,false 表示是进度条,true 表示是个走马灯
        builder.setTicker (title);// 设置 title
        builder.setWhen(System.currentTimeMillis());
        builder.setContentTitle (content);// 设置内容
        builder.setAutoCancel (true);// 点击消失
        builder.setSmallIcon(R.drawable.upload);
        builder.setContentIntent (PendingIntent.getActivity (context, 0, new Intent (), 0));// 这句和点击消失那句是 “Notification 点击消失但不会跳转” 的必须条件,如果只有点击消失那句,这个功能是不能实现的

        Notification noti = builder.getNotification();
        mNotificationManager.notify(id,noti);

希望这个例子对其他人有点用,因为我特曾为这个功能苦恼过,呵呵!


Android Notification 详解 —— 响应 notification 事件

Android Notification 详解 —— 响应 notification 事件

上一篇讲了如何创建并显示一个 notification,这一篇就总结下点击 notification 后,程序应该如何响应。

 

一般来讲,点击一个 notification 后,都会打开一个 Activity 做为对点击事件的响应,这个 Activity 是之前在 PendingIntent 中设置好的。

经常玩 Android 手机的应该都有印象,在日历应用中,你新建一个提醒,当提醒通知收到后,你点击通知,会进入提醒的内容页面,如果这个时候按 back 键,会直接退出应用。

但是在 Gmail 的应用中,如果有一封新邮件到来,那么点击通知后,会进入到邮件的内容页面,等你看完邮件,点击 back 键,会退到邮件列表页面,再按 back 键,才会退出应用。

 

我们总结一下两种情况,假设我们的应用有两个 Activity(ParentActivity、SubActivity),notification 中设置打开的 Activity 为 SubActivity。

那么第一种情况就是:

点击 Notification ——> 进入 SubActivity ——> back 键 ——> 退出应用

第二种情况:

点击 Notification ——> 进入 SubActivity ——> back 键 ——> 退到 ParentActivity ——>back 键 ——> 退出应用

 

第一种情况比较简单,只需要在 PendingIntent 中指定 Activity,不需要其他设置,Android 默认的就这样。

PendingIntent contentIntent = PendingIntent.getActivity(context, 0,  intent, PendingIntent.FLAG_CANCEL_CURRENT);

但是在创建 PendingIntent 的时候需要注意参数 PendingIntent.FLAG_CANCEL_CURRENT

这个标志位用来指示:如果当前的 Activity 和 PendingIntent 中设置的 intent 一样,那么久先取消当前的 Activity,用 PendingIntent 中指定的 Activity 取代之。

另外,需要在 Manifest 中对指定的 Activity 设置属性

<activity android:name=".SubActivityl"  
        android:launchMode="singleTask"  
        android:taskAffinity=""  
        android:excludeFromRecents="true">  
</activity>

第二种情况稍微复杂点,因为如果只打开一个 SubActivity,程序并没办法知道他的上一级 Activity 是谁,所以需要在点击 Notification 时打开一组 Activity,但是我们并不需要一个个去调用 startActivity 方法,PendingIntent 提供了个静态方法 getActivities,里面可以设置一个 Intent 数组,用来指定一系列的 Activity。

所以我们首先写一个函数创建一个 Activity 数组:

Intent[] makeIntentStack(Context context) {  
    Intent[] intents = new Intent[2];  
    intents[0] = Intent.makeRestartActivityTask(new ComponentName(context, com.example.notificationtest.MainActivity.class));  
    intents[1] = new Intent(context,  com.example.notificationtest.SubActivity.class);  
    return intents;  
}

其中需要注意的是 Intent.makeRestartActivityTask 方法,这个方法用来创建 activity 栈的根 activity

接下来,创建并显示 Notification:

void showNotification(Intent intent) {  
    Notification notification = new Notification(  
            R.drawable.status_icon,   
            "Hello World ticker text",  
            System.currentTimeMillis());  
  
    PendingIntent contentIntent = PendingIntent.getActivities(  
            this,  
            0,  
            makeIntentStack(this),   
            PendingIntent.FLAG_CANCEL_CURRENT);  
    notification.setLatestEventInfo(  
            this,   
            "Title",  
            "Hey, shall we have a dinner tonight",   
            contentIntent);  
    notification.flags |= Notification.DEFAULT_ALL;  
  
    mNM.notify(1, notification);  
}


Android NotificationCompat通知消息

Android NotificationCompat通知消息

import android.os.Bundle;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.app.NotificationCompat;
import android.view.View;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void click(View v){
        NotificationCompat.Builder builder = 
                new NotificationCompat.Builder(this);
        //设置标题
        builder.setContentTitle("通知标题");
        
        builder.setContentText("这是内容。。。。。。。。。。。。。。");
        //图标
        builder.setSmallIcon(R.drawable.ic_launcher);
        //就是通知打开前在,页面可以看见的提示文字
        builder.setTicker("一闪,搜索");
        
        
        /**
         * 设置notification的样式
         */
        
        //大文本类型的通知
        NotificationCompat.BigTextStyle big = new NotificationCompat.BigTextStyle();
        big.setBigContentTitle("大的标题").bigText("大的内容");
        //设置builder的样式
        //builder.setStyle(big);
        
        //大图片的类型
        NotificationCompat.BigPictureStyle bigimg = new NotificationCompat.BigPictureStyle();
        
        Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        
        bigimg.bigLargeIcon(b);
        //设置样式
        //builder.setStyle(bigimg);
        /**
         * 可以显示更多文字
         */
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        inboxStyle.addLine("一行文本");
        inboxStyle.addLine("2行文本");
        inboxStyle.addLine("3行文本");
        inboxStyle.addLine("4行文本");
        inboxStyle.addLine("5行文本");
        builder.setStyle(inboxStyle);
        
        /**
         * 设置跳转,预跳转。可点可不点
         * 
         */
        Intent intent = new Intent(this,MainActivity.class);
        /**
         * 
         * pendingIntent:封装了Intent的预意图,表示
         * 动作还没有发生,但是会一直保留着这个动作
         * context 上下文
         * requestCode:请求码 
         * intent :跳转意图
         * Flag:标记
         */
        PendingIntent pendingIntent = 
                PendingIntent.getActivity(this, 200, intent, PendingIntent.FLAG_ONE_SHOT);
        
        //PendingIntent.FLAG_NO_CREATE;一般用一个
        builder.setContentIntent(pendingIntent);
        
        
        //服务来调用
        /**
         * get 是系统的服务
         * 传递Context.NOTIFICATION_SERVICE 可以获取一个管理Notification 的管理器 
         * 
         */
        NotificationManager manager = 
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        /**
         * builder构造器,可以建造哟个Notification对象
         * 
         */
        Notification build = builder.build();
        
        /**
         * 这个方法可以发出一个通知
         * id 唯一标识的id号
         * 
         * notification 是需要发出通知的对象,(谁需要这个通知)
         */
        manager.notify(1, build);
    }
}


今天的关于Android中通过Notification&NotificationManager实现消息通知android获取通知的分享已经结束,谢谢您的关注,如果想了解更多关于Android Notification 消息通知 相关资料.md、android Notification 的一个简单应用(在 Notification 中嵌入一个进度条,并且这个 Notification 点击消失但不会跳转)、Android Notification 详解 —— 响应 notification 事件、Android NotificationCompat通知消息的相关知识,请在本站进行查询。

本文标签: