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 正则匹配 提取所有 preg_match_all matchAll方法
javascript 提取全部的的方法.javascript中没有matchAll这种方法. 用while来实现类似 PHP 中的preg_match_all() :(by default7#zbph ...
- mysql语句在node.js中的写法
总结一下mysql语句在node.js中的各种写法,参考了npm网站mysql模块给的实例. 查询 select //1 db.query('select * from tuanshang_users ...
- 【Android进阶】Activity的四种加载模式
Activity的四种加载模式: 1.standard :系统的默认模式,一次跳转即会生成一个新的实例.假设有一个activity命名为Act1, 执行语句:startActivity(new Int ...
- RH033读书笔记(14)-Lab 15 Switching Users and Setting a Umask
Lab 15 Switching Users and Setting a Umask Goal: Become familiar with the use of several essential c ...
- 利用hibernate的session查询数据库,而且在jsp页面显示表内容的方法
试过了非常多种方法都没有成功,最终让我找到了这样的方法! 首先在后台写代码: Transaction tx = session.beginTransaction(); List list = sess ...
- 读书时间《JavaScript高级程序设计》二:面向对象
接着上次的进度,开始看第6章. 第6章 面向对象的程序设计 理解对象 创建自定义对象最简单的方式就是创建一个 Object 的实例,然后为它添加属性和方法. var person = new Obje ...
- ASP中文件上传组件ASPUpload介绍和使用方法
[导读]要实现该功能,就要利用一些特制的文件上传组件.文件上传组件网页非常多,这里介绍国际上非常有名的ASPUpload组件 1 下载和安装ASPUpload 要实现该功能,就要利用一些特制的文件上 ...
- 《TCP/IP作品详细解释2:达到》注意事项--ARP:地址解析协议
Net/3于ARP和实施密切与路由表相关联的,下图显示了我们的叙述性说明ARP使用样品. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvVE9ERDkxMQ ...
- c#里listview里如何获取点击的是哪一列
很多时候c#里会用到listview,又会给它添加很多的列,可以设置点击列的标头实现按照这列的内容排序等功能,然而点击不同列排序的方法是不一样的,这时候就需要知道,我到底是点击了哪一列,比如点击名字列 ...
- Struts2 + uploadify 多文件上传完整的例子!
首先,我这里使用的是 Jquery Uploadify3.2版本号 导入相关的CSS JS <link rel="stylesheet" type=" ...