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(一个)——使用演示样本的基础知识的更多相关文章

  1. 弄一个ajax笔记方便查询-基础知识篇

    jQuery对Ajax做了大量的封装,jQuery采用了三层封装: 最底层的封装方法为:$.ajax() 通过最底层进一步封装了第二层的三种方法:.load().$.get().$.post() 最高 ...

  2. 背水一战 Windows 10 (78) - 自定义控件: 基础知识, 依赖属性, 附加属性

    [源码下载] 背水一战 Windows 10 (78) - 自定义控件: 基础知识, 依赖属性, 附加属性 作者:webabcd 介绍背水一战 Windows 10 之 控件(自定义控件) 自定义控件 ...

  3. 背水一战 Windows 10 (76) - 控件(控件基类): Control - 基础知识, 焦点相关, 运行时获取 ControlTemplate 和 DataTemplate 中的元素

    [源码下载] 背水一战 Windows 10 (76) - 控件(控件基类): Control - 基础知识, 焦点相关, 运行时获取 ControlTemplate 和 DataTemplate 中 ...

  4. 背水一战 Windows 10 (75) - 控件(控件基类): FrameworkElement - 基础知识, 相关事件, HorizontalAlignment, VerticalAlignment

    [源码下载] 背水一战 Windows 10 (75) - 控件(控件基类): FrameworkElement - 基础知识, 相关事件, HorizontalAlignment, Vertical ...

  5. 背水一战 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 ...

  6. 背水一战 Windows 10 (50) - 控件(集合类): ItemsControl - 基础知识, 数据绑定, ItemsPresenter, GridViewItemPresenter, ListViewItemPresenter

    [源码下载] 背水一战 Windows 10 (50) - 控件(集合类): ItemsControl - 基础知识, 数据绑定, ItemsPresenter, GridViewItemPresen ...

  7. 背水一战 Windows 10 (56) - 控件(集合类): ListViewBase - 基础知识, 拖动项

    [源码下载] 背水一战 Windows 10 (56) - 控件(集合类): ListViewBase - 基础知识, 拖动项 作者:webabcd 介绍背水一战 Windows 10 之 控件(集合 ...

  8. js基础知识易错点(一)

    最近替另一个项目招人,要求基础知识好,随便问了一些基础题,发现了一些易错的点,总结一下. 1.判断一个空数组 var arr = []; 1)JSON.stringify(arr) == " ...

  9. mysql基础知识语法汇总整理(一)

    mysql基础知识语法汇总整理(二)   连接数据库操作 /*连接mysql*/ mysql -h 地址 -P 端口 -u 用户名 -p 密码 例如: mysql -u root -p **** /* ...

随机推荐

  1. 未能加载文件或程序集“Common”或它的某一个依赖项。试图加载格式不正确的程序

    原因:操作系统是64位的,但发布的程序引用了一些32位的ddl,所以出现了兼容性的问题解决方案一:如果是64位机器,IIS——应用程序池——高级设置——启用32位应用程序 :true.解决方案二:修改 ...

  2. SPPS java 创template

    最近写信给学校一个部门java plug for spss. 当加到变量超过70个月,然后保存,SPSS它会在错误的地方报. 解决方案: 每添加70提交变量. 版权声明:本文博主原创文章.博客,未经同 ...

  3. JAVA对数据库进行操作,实现数据库中数据的插入,查询,更改,删除操作

    (—)通过mysql workbench 创建一个数据库,在这里命名为company,然后建一个tb_employee表 (二)以下是java代码对表tb_employee的操作 1 创建一个Empl ...

  4. 使用 gridfs-stream 存储文件遇到的一个坑。

    前一段时间参读了某个coder写的用 gridfs-stream 来存储文件,感觉不错就自己用 gridfs-stream 模块写了一个文件存储服务,但是发现存储的文件总是删不掉, 我调用的是GFS的 ...

  5. ZOJ 3795 Grouping(Tarjan收缩点+DAG)

    Suppose there are N people in ZJU, whose ages are unknown. We have some messages about them. The i-t ...

  6. HDU ACM 1290 献给杭电五十周年校庆的礼物

    解析: 1.n条直线把平面切割成的区域数为: f(n)=f(n-1)+n=n(n+1)/2+1; 2.把空间切割为最多区域数的时候,第n个平面与前(n-1)个平面相交.且无三面共线,因此该平面与前(n ...

  7. Cocos2d-x源代码解析(1)——地图模块(3)

    接上一章<Cocos2d-x源代码解析(1)--地图模块(2)> 通过前面两章的分析,我们能够知道cocos将tmx的信息结构化到 CCTMXMapInfo.CCTMXTilesetInf ...

  8. ImageView建立selector在录音中遇到的小问题及解决方案

    随着两张照片做了一个selector,采用ImageView的src要么background采用selector当点击,总不会出现点击效果,这就是为什么?经过一番折腾,后来发现"揭秘&quo ...

  9. ssh配置连接

    SSH构造: 1.改动vi /etc/ssh/sshd_config,依据模板将要改动的參数凝视去掉并改动參数值: Port 22 指定SSH连接的port号,安全方面不建议使用默认22port Pr ...

  10. 浅析Java中的final关键字(转)

    谈到final关键字,想必很多人都不陌生,在使用匿名内部类的时候可能会经常用到final关键字.另外,Java中的String类就是一个final类,那么今天我们就来了解final这个关键字的用法.下 ...