Notification(一个)——使用演示样本的基础知识
main.xml如下面:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
> <Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button"
android:textSize="20sp"
android:layout_centerInParent="true"
/> </RelativeLayout>
another.xml例如以下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/newActivity"
android:textSize="20sp"
android:layout_centerInParent="true"
/> </RelativeLayout>
MainActivity例如以下:
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
/**
* Demo描写叙述:发送系统通知
* 注意:
* 1 PendingIntent的使用
* 2 权限申请
*
*/
public class MainActivity extends Activity {
private Button mButton;
private final int FIRST=1;
private final int SECOND=2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
private void init(){
mButton=(Button) findViewById(R.id.button);
mButton.setOnClickListener(new ButtonOnClickListenerImpl());
}
private class ButtonOnClickListenerImpl implements OnClickListener{
@Override
public void onClick(View v) {
NotificationManager manager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Intent firstIntent=new Intent();
PendingIntent firstPendingIntent=PendingIntent.getActivity(MainActivity.this, 0, firstIntent, 0);
Notification firstNotification=new Notification();
//设置通知的图标
firstNotification.icon=R.drawable.ic_launcher;
//设置状态栏的通知提示信息
firstNotification.tickerText=getResources().getString(R.string.firstNotification_ticker);
//设置通知发送时间
firstNotification.when=System.currentTimeMillis();
//採用系统默认的声音,震动,闪光灯
firstNotification.defaults=Notification.DEFAULT_ALL;
//打开应用程序后图标消失
firstNotification.flags|=Notification.FLAG_AUTO_CANCEL;
//设置通知的标题和内容,以及点击通知后的对应操作.此处无操作.
//注意:假设将该方法最后一个參数设置为null,则报错
firstNotification.setLatestEventInfo(MainActivity.this,
getResources().getString(R.string.firstNotification_title),
getResources().getString(R.string.firstNotification_content),
firstPendingIntent);
//发送第一个通知
manager.notify(FIRST, firstNotification); Intent secondIntent=new Intent(MainActivity.this,AnotherActivity.class);
PendingIntent secondPendingIntent=PendingIntent.getActivity(MainActivity.this, 0, secondIntent, 0);
Notification secondNotification=new Notification();
//设置通知的图标
secondNotification.icon=R.drawable.ic_launcher;
//设置状态栏的通知提示信息
secondNotification.tickerText=getResources().getString(R.string.secondNotification_ticker);
//设置通知发送时间
secondNotification.when=System.currentTimeMillis();
//採用系统默认的声音,震动,闪光灯
secondNotification.defaults=Notification.DEFAULT_ALL;
//打开应用程序后图标消失
secondNotification.flags|=Notification.FLAG_AUTO_CANCEL;
//设置通知的标题和内容,以及点击通知后的对应操作.此处为打开指定的Activity
//注意:假设将该方法最后一个參数设置为null,则报错
secondNotification.setLatestEventInfo(MainActivity.this,
getResources().getString(R.string.secondNotification_title),
getResources().getString(R.string.secondNotification_content),
secondPendingIntent);
//发送第二个通知
manager.notify(SECOND, secondNotification); } }
}
AnotherActivity例如以下:
import android.app.Activity;
import android.os.Bundle;
public class AnotherActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.another);
}
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
Notification(一个)——使用演示样本的基础知识的更多相关文章
- 弄一个ajax笔记方便查询-基础知识篇
jQuery对Ajax做了大量的封装,jQuery采用了三层封装: 最底层的封装方法为:$.ajax() 通过最底层进一步封装了第二层的三种方法:.load().$.get().$.post() 最高 ...
- 背水一战 Windows 10 (78) - 自定义控件: 基础知识, 依赖属性, 附加属性
[源码下载] 背水一战 Windows 10 (78) - 自定义控件: 基础知识, 依赖属性, 附加属性 作者:webabcd 介绍背水一战 Windows 10 之 控件(自定义控件) 自定义控件 ...
- 背水一战 Windows 10 (76) - 控件(控件基类): Control - 基础知识, 焦点相关, 运行时获取 ControlTemplate 和 DataTemplate 中的元素
[源码下载] 背水一战 Windows 10 (76) - 控件(控件基类): Control - 基础知识, 焦点相关, 运行时获取 ControlTemplate 和 DataTemplate 中 ...
- 背水一战 Windows 10 (75) - 控件(控件基类): FrameworkElement - 基础知识, 相关事件, HorizontalAlignment, VerticalAlignment
[源码下载] 背水一战 Windows 10 (75) - 控件(控件基类): FrameworkElement - 基础知识, 相关事件, HorizontalAlignment, Vertical ...
- 背水一战 Windows 10 (63) - 控件(WebView): 基础知识, 加载 html, http, https, ms-appx-web:///, embedded resource, ms-appdata:///, ms-local-stream://
[源码下载] 背水一战 Windows 10 (63) - 控件(WebView): 基础知识, 加载 html, http, https, ms-appx-web:///, embedded res ...
- 背水一战 Windows 10 (50) - 控件(集合类): ItemsControl - 基础知识, 数据绑定, ItemsPresenter, GridViewItemPresenter, ListViewItemPresenter
[源码下载] 背水一战 Windows 10 (50) - 控件(集合类): ItemsControl - 基础知识, 数据绑定, ItemsPresenter, GridViewItemPresen ...
- 背水一战 Windows 10 (56) - 控件(集合类): ListViewBase - 基础知识, 拖动项
[源码下载] 背水一战 Windows 10 (56) - 控件(集合类): ListViewBase - 基础知识, 拖动项 作者:webabcd 介绍背水一战 Windows 10 之 控件(集合 ...
- js基础知识易错点(一)
最近替另一个项目招人,要求基础知识好,随便问了一些基础题,发现了一些易错的点,总结一下. 1.判断一个空数组 var arr = []; 1)JSON.stringify(arr) == " ...
- mysql基础知识语法汇总整理(一)
mysql基础知识语法汇总整理(二) 连接数据库操作 /*连接mysql*/ mysql -h 地址 -P 端口 -u 用户名 -p 密码 例如: mysql -u root -p **** /* ...
随机推荐
- 读书时间《JavaScript高级程序设计》七:表单
在HTML中表单是有<form>元素表示,在JS中表单对应的是HTMLFormElement类型. 表单自有的属性和方法: 获取表单 1. 通过ID document.getElemen ...
- Android访问设置
在需求 AndroidManifest.xml 中增加下面代码: (1)假设应用程序须要訪问网络权限 <uses-permission android:name="android.pe ...
- 上curl java 模拟http请求
最近,我的项目要求java模拟http请求,获得dns解决 tcp处理过的信息特定的连接. java api提供urlConnection apache提供的httpClient都不能胜任该需求,二次 ...
- 香蕉派路由功Openwrt、Android功耗对照測试
路由这个东西是要长期通电使用的,所以功耗也是须要关注的.如今香蕉派路由已经有了openwrt和android两个 系统,这两个系统的功耗是否一样呢? 測试工具:QUIGG的德国产功耗測试仪一个.手机充 ...
- HDU 3831 DICS
意甲冠军: 按标题给4操作模式 用最少的次数 离a串行转换b弦 思路: 因为操作仅仅有这4种 所以我们能够确定从头到位去匹配a和b一定是正确的 那么状态数一共同拥有多少呢 一共同拥有lengt ...
- [原] Jenkins Android 自动打包配置(转)
一.Jenkins自动打包配置 目标:1. 自动打包:2. 自动上传:3. 友好下载 1. Jenkins简介 Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作. 减少重复劳 ...
- iOS开发无第三方控件的援助达到的效果侧边栏
最近的研究iOS程序侧边栏.渐渐的发现iOS该方案还开始采取风侧边栏格该,QQ,今日头条,Path(Path运营商最早的侧边栏app该,效果说成是Path效果),所以就研究了下. 然后发现Git Hu ...
- 必须掌握的八个cmd命令
原文:必须掌握的八个cmd命令 一.ping 它是用来检查网络是否通畅或者网络连接速度的命令.作为一个生活在网络上的管理员或者黑客来说,ping命令是第一个必须掌握的DOS命令,它所利用的原理是这样的 ...
- POJ 2431 Expedition (贪心+优先队列)
题目地址:POJ 2431 将路过的加油站的加油量放到一个优先队列里,每次当油量不够时,就一直加队列里油量最大的直到能够到达下一站为止. 代码例如以下: #include <iostream&g ...
- SCM文章4教训:定时器共阴极LED动态显示屏
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQva290ZWlfODhfbHVsdWNfNjY=/font/5a6L5L2T/fontsize/400/fil ...