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. Directx11学习笔记【十】 画一个简单的三角形

    本篇笔记要实现的是在屏幕上渲染出一个三角形,重点要学习的是渲染一个几何体的流程方式. 为了渲染几何图形,需要一个顶点缓存和一个描述顶点布局的输入层,还有着色器(主要是顶点着色器和像素着色器),下面来看 ...

  2. HDU 4067 Random Maze

    意甲冠军: 一个"随机图"它被定义为具有以下性质如: 一个入口和一个出口 有向图 对于入口  出度比入度大1 对于出口  入度比出度大1 对于其它点  入度等于出度 现给出一幅有向 ...

  3. iOS8发展~Swift(三)UI详细解释

    一个.总结 使用Swift去完成iOS的UI接口,事实上,目前的想法和OC实现几乎一致,只是在措辞非常大的差异,修改前更更大的个人控制.为有纯代码强迫症,所以接下来创建一个纯代码动项目,然后在此基础上 ...

  4. HDU 4864Task(更多的联合培训学校1)(贪婪)

    职务地址:pid=4864">HDU4864 这题又是一上来觉得是最小费用流,可是边太多.果然,敲完交上去后不断TLE.. 小优化了两次也没过. . . sad.. 后来看了题解才发现 ...

  5. 汉字Collection

    只是上一行Demo private static string[] HanZis = new string[]{ "啊阿呵吖嗄腌锕爱矮挨哎碍癌艾唉哀蔼隘埃皑呆嗌嫒瑷暧捱砹嗳锿霭按安暗岸俺案鞍 ...

  6. Ubuntu 14.04 Android 使用Maven一个 用例project

    在说明书前面描述SDK通过使用Ant发展. 本文试图在此基础上使用Maven发展. 在这里,我们需要使用maven-android-plugin. 在本文中,参考官方文件: https://code. ...

  7. 给AspNetPager分页控件添加bootstrap样式

    AspNetPager分页控件算是比较好用的一个分页控件了.想要结合bootstrap使用,官方代码入口 .pagination a[disabled]{ color: #777;cursor: no ...

  8. SQL Server 连接问题-TCP/IP

    原文:SQL Server 连接问题-TCP/IP 出自:http://blogs.msdn.com/b/apgcdsd/archive/2012/02/24/ms-sql-server-tcp-ip ...

  9. A*寻路算法lua实现

    前言:并在相当长的时间没有写blog该,我觉得有点"颓废"该,最近认识到各种同行,也刚刚大学毕业,我认为他们是优秀的.认识到与自己的间隙,有点自愧不如.我没有写blog当然,部分原 ...

  10. oracle 11g 基于磁盘的备份rman duplicate

    基于磁盘的备份rman duplicate 命令创建standby database 前提条件: 确保原始库数据库的备份.存档standby 结束是完全可见, 这里,如果原始文库和靶 - 侧数据文件, ...