Notification是安卓手机顶部的消息提示

这里我们分别设置两个按钮,来实现顶部消息的发送和取消

功能实现

首先要在主Activity中设置一个通知控制类

NotificationManager manager; //通知控制类

然后在onCreate方法中获取系统服务

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

接着设置通知栏信息

 private void sendNotification() {
Intent intent = new Intent(this,MainActivity.class);
PendingIntent pintent = PendingIntent.getActivity(this,0,intent,0);
Builder builder = new Builder(this);
builder.setSmallIcon(R.mipmap.ic_launcher);//设置图标
builder.setTicker("hello");//设置手机状态栏提示
builder.setWhen(System.currentTimeMillis());//时间
builder.setContentTitle("通知通知栏");//标题
builder.setContentText("我是小浩");//通知内容
builder.setContentIntent(pintent);//点击后的意图
builder.setDefaults(Notification.DEFAULT_ALL);//给通知设置震动,声音,和提示灯三种效果,不过要记得申请权限
Notification notification = builder.build(); //4.1版本以上用这种方法
//builder.getNotification(); //4.1版本以下用这种方法
manager.notify(notification_ID,notification);
}

在Mainfest文件中加入 震动和提示灯权限

 <uses-permission android:name="android.permission.VIBRATE"></uses-permission>
<uses-permission android:name="android.permission.FLASHLIGHT"></uses-permission>

Android 之 信息通知栏消息Notification的更多相关文章

  1. Android Q 使用通知栏消息

    String myChannelId = "iot"; String myChannelName = "告警通知服务"; NotificationManager ...

  2. android开发之Intent.setFlags()_让Android点击通知栏信息后返回正在运行的程序

    android开发之Intent.setFlags()_让Android点击通知栏信息后返回正在运行的程序     在应用里使用了后台服务,并且在通知栏推送了消息,希望点击这个消息回到activity ...

  3. android实现通知栏消息

    一.原理 消息推送有两种,一种是客户端定时直接到服务器搜索消息,如果发现有新的消息,就获取消息下来:另一种是服务器向客户端发送消息,也就是当有信息消息时,服务器端就会向客户端发送消息. 二.步骤(代码 ...

  4. Android种使用Notification实现通知管理以及自定义通知栏(Notification示例四)

    示例一:实现通知栏管理 当针对相同类型的事件多次发出通知,作为开发者,应该避免使用全新的通知,这时就应该考虑更新之前通知栏的一些值来达到提醒用户的目的.例如我们手机的短信系统,当不断有新消息传来时,我 ...

  5. 通知栏发送消息Notification(可以使用自定义的布局)

    一个简单的应用场景:假如用户打开Activity以后,按Home键,此时Activity 进入-> onPause() -> onStop() 不可见.代码在此时机发送一个Notifica ...

  6. React Native之通知栏消息提示(android)

    React Native之通知栏消息提示(android) 一,需求分析与概述 1.1,推送作为手机应用的基本功能,是手机应用的重要部分,如果自己实现一套推送系统费时费力,所以大部分的应用都会选择使用 ...

  7. Android中使用Notification实现进度通知栏(Notification示例三)

    我们在使用APP的过程中,软件会偶尔提示我们进行版本更新,我们点击确认更新后,会在通知栏显示下载更新进度(已知长度的进度条)以及安装情况(不确定进度条),这就是我们今天要实现的功能.实现效果如下: 在 ...

  8. Android开发学习之路--Notification之初体验

    一般当我们收到短信啊,微信啊,或者有些app的提醒,我们都会在通知栏收到一天简单的消息,然后点击消息进入到app里面,其实android中有专门的Notification的类可以完成这个工作,这里就实 ...

  9. android 自己定义通知栏遇到的问题

    首先看报错信息: E/AndroidRuntime(12220): FATAL EXCEPTION: main E/AndroidRuntime(12220): Process: gn.com.and ...

随机推荐

  1. CentOS 6.8安装Docker V1.0

    rpm -Uvh http://dl.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm yum -y install do ...

  2. angular复选框式js树形菜单(二)

    删除(过滤)树形结构某一个子节点: function filterTreeData(treeData){ angular.forEach(treeData,function(item){ if (it ...

  3. 2017.11.28 Enginering management:problem-solving ability

    Today,my colleague is on bussiness trip. going to customer factory in jiangxi. slove the color diffe ...

  4. uva10892(暴力枚举)

    把n的所有因子求出来,总数不会太多,所以直接O(n2)的暴力枚举所有对行不行. 有几个细节要注意,详见代码. #include<iostream> #include<cstdio&g ...

  5. 转载:【菜鸟玩Linux开发】通过MySQL自动同步刷新Redis

    转载: http://www.cnblogs.com/zhxilin/archive/2016/09/30/5923671.html

  6. 利用sort对数组快速排序

    // sort内部使用快速排序,每次比较两个元素大小的时候如果没有参数,则直接判断字母表,如果有参数,则把正在比较的两个参数传入自定义方法并调用(正在比较的两个数会传给自定义方法的v1.v2),如果返 ...

  7. Apache Htpasswd生成和验证密码

    Assuming you create the password using the following command and "myPassword" as the passw ...

  8. 蓝桥杯 基础练习 BASIC-25 回形取数

    基础练习 回形取数   时间限制:1.0s   内存限制:512.0MB 问题描述 回形取数就是沿矩阵的边取数,若当前方向上无数可取或已经取过,则左转90度.一开始位于矩阵左上角,方向向下. 输入格式 ...

  9. POJ1020(小正方形铺大正方形)

    Anniversary Cake Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16579   Accepted: 5403 ...

  10. Java-API-Package:java.math

    ylbtech-Java-API-Package:java.math 1.返回顶部 1. Package java.math Provides classes for performing arbit ...