Notification通知栏
Notification通知栏
首先实现的功能就是通知栏显示Notification,Notification是显示在系统的通知栏上面的,所以Notification
是属于进程之前的通讯。进程之间的通讯是要在系统中获取系统的服务的。
1.NotificationManager nm=(NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
接下就是把Notification类用NotificationManager来管理。
2.nm.notify(0, notification);
然后Notification还是设置内容,标题、图标、内容、跳转。
代码功能:实现Notification中的通知栏打电话给110,别忘了Manifest.xml中的权限
<uses-permission android:name="android.permission.CALL_PHONE"/>
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void click(View view){
NotificationManager nm=(NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
Notification notification=new Notification(R.drawable.ic_launcher, "我是一条消息", System.currentTimeMillis());
notification.flags=Notification.FLAG_AUTO_CANCEL;
Intent intent=new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:110"));
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(this, "标题", "内容", contentIntent);
nm.notify(0, notification);
}
}
XML中的文件
activity_main.xml
<RelativeLayout 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"
tools:context=".MainActivity" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" /> <Button
android:onClick="click"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn"
android:layout_centerInParent="true"
android:text="点击显示通知栏"
/> </RelativeLayout>
Notification通知栏的更多相关文章
- android自定义Notification通知栏实例
项目有个需求,需要在发送Notification的时候动态给定url的图片.大概思路如下:自己定义一个Notification的布局文件,这样能够很方便设置View的属性. 首先加载网络图片,使用Bi ...
- 安卓开发笔记——Notification通知栏
当用户有没有接到的电话的时候,Android顶部状态栏里就会出现一个小图标.提示用户有没有处理的快讯,当拖动状态栏时,可以查看这些快讯.Android给我们提供了NotificationManager ...
- Android Notification通知栏的使用,通知栏在Android8.0系统不显示的问题;
1.正常使用通知栏: /** * 创建通知栏管理工具 */ NotificationManager notificationManager = (NotificationManager) getSys ...
- Notification通知栏的使用
一.基础的知识了解 1.pendingIntent : 它是Intent的封装,可以跳转某个Activity.给Service发送一个命令.还可以发送一个广播 2.进度条的使用方法 3.更新通知栏的信 ...
- Android学习(二十)Notification通知栏
一.通知栏的内容 1.图标 2.标题 3.内容 4.时间 5.点击后的相应 二.如何实现通知栏 1.获取NotificationManager. 2.显示通知栏:notify(id,notificat ...
- Android Notification通知栏使用
package com.example.mynotifycation; import android.app.Activity; import android.app.Notification; im ...
- 22 Notification 通知栏代码
结构图: MainActivity.java package com.qf.day22_notification; import android.app.Activity; import androi ...
- 安卓开发_浅谈Notification(通知栏)
Notification通知栏是显示在手机状态的消息,代表一种全局效果的通知 快速创建一个Notification的步骤简单可以分为以下四步: 第一步:通过getSystemService()方法得到 ...
- Notification NotificationManager RemoteViews PendingIntent
Notification和NotificationManager :可以用来实现可视化的消息通知等,比如:下载进度显示,消息显示,广播的内容等 RemoteViews :用于创建自定义的Notific ...
随机推荐
- Windows7睡眠后自动唤醒
笔者的电脑(Windows7 64位旗舰版)睡眠后,隔段时间后会自动唤醒.经两项配置后,解决了该问题. 1 禁用唤醒定时器 控制面板里进入"电源选项""更改计划设置&qu ...
- 【转】 STL中的set容器的一点总结
1.关于set C++ STL 之所以得到广泛的赞誉,也被很多人使用,不只是提供了像vector, string, list等方便的容器,更重要的是STL封装了许多复杂的数据结构算法和大量常用数据结构 ...
- eclipse ssh连接sqlserver express
public static String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; public stati ...
- C/C++中的abort、atexit、exit和_Exit
这几个函数都在头文件#include <stdlib.h>中声明.exit._Exit与abort函数使程序终止,控制并不返回到这些函数的调用者. exit()函数 void exit(i ...
- 一个比较全面的java随机数据生成工具包
最近,由于一个项目的原因需要使用一些随机数据做测试,于是写了一个随机数据生成工具,ExtraRanom.可以看成是Java官方Random类的扩展,主要用于主要用于测试程序.生成密码.设计抽奖程序等情 ...
- robotframework笔记9
列表和字典 通过专用关键字创建了列表和字典.我们将在这里看到创建的两个例子 ︰ 选择 *** Settings *** Library BuiltIn Library Collections *** ...
- [Jetty] jetty 内存调优
在start.ini中配置代码如下 -Dcom.sun.management.jmxremote=true -Xmx6144m -XX:PermSize=256M -XX:MaxPermSize=10 ...
- python 基础学习(字典对象,set对象)
1.dict 字典对象 a.定义对象 d={'a':14,'b':12}b.通过key获取value d['a'] 方法1.判断key是否存在 if 'a' in d: d['a']方法2:通过用ge ...
- Css:背景色透明,内容不透明之终极方法!兼容所有浏览器
转载 http://www.cnblogs.com/jikey/archive/2012/08/31/2665880.html <!DOCTYPE html PUBLIC "-//W3 ...
- Java 之 I/O 系列 02 ——序列化(二)
Java 之 I/O 系列 目录 Java 之 I/O 系列 01 ——基础 Java 之 I/O 系列 02 ——序列化(一) Java 之 I/O 系列 02 ——序列化(二) 继续上篇的第二个问 ...