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 ...
随机推荐
- VB6 GDI+ 入门教程[2] GDI+初始化
http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[2] GDI+初始化 2009 年 6 月 18 日 7 ...
- C 语言字符串连接的 3种方式
C 语言字符串连接的 3种方式 #include<stdio.h> #include<stdlib.h> #include<string.h> char *join ...
- MySQL OCP 考试,一个不错的网站
http://www.aiotestking.com/oracle/category/exam-1z0-883-mysql-5-6-database-administrator/page/10/ 里面 ...
- Node.js 开发模式(设计模式)
Asynchronous code & Synchronous code As we have seen in an earlier post (here), how node does th ...
- php 变量原理
1.php作为一种弱类型语言,不需要显式的指明变量的类型,但是php变量也是有类型的,php变量包含以下8种变量(三大类) a.标量类型:boolean,integer,float(double),s ...
- [bootstrap] bootstrap 简介和相关网址
Bootstrap 来自 Twitter,是目前很受欢迎的前端框架. 基于 HTML.CSS.JAVASCRIPT ,简洁灵活,使 Web 开发更加快捷. Bootstrap提供了优雅的HTML和CS ...
- hdu 1520
Anniversary party Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- ocument的createDocumentFragment()方法
在<javascript高级程序设计>一书的6.3.5:创建和操作节点一节中,介绍了几种动态创建html节点的方法,其中有以下几种常见方法: · crateAttribute(name): ...
- Java多线程-新特征-锁(上)
在Java5中,专门提供了锁对象,利用锁可以方便的实现资源的封锁,用来控制对竞争资源并发访问的控制,这些内容主要集中在java.util.concurrent.locks 包下面,里面有三个重要的接口 ...
- [转]Integer.valueOf(String) 方法之惑
具体问题以前偶然遇到过,好象是一个java答题得分的论坛,当时做错还研究了下怎么回事,但是前两天遇到类似问题却没想起来.巩固下基础,转了下面文章. 以下内容转自:http://www.importne ...