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. 【C语言探索之旅】 第一部分第九课:函数

    内容简介 1.课程大纲 2.第一部分第九课:函数 3.第一部分第十课预告: 练习题+习作 课程大纲 我们的课程分为四大部分,每一个部分结束后都会有练习题,并会公布答案.还会带大家用C语言编写三个游戏. ...

  2. c# winform 中的 工具栏自动隐藏 splitter用法 带源码

    c# winform 中的 工具栏自动隐藏 splitter用法 带源码 代码下载地址 http://download.csdn.net/detail/simadi/7649313

  3. 初探swift语言的学习笔记五(线程)

    作者:fengsh998 原文地址:http://blog.csdn.net/fengsh998/article/details/30354127 转载请注明出处 假设认为文章对你有所帮助,请通过留言 ...

  4. nyist 488 素数环(搜索+回溯)

     素数环 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 有一个整数n,把从1到n的数字无反复的排列成环,且使每相邻两个数(包含首尾)的和都为素数,称为素数环. ...

  5. Python 获取Twitter用户与Friends和Followers的关系(eg, 交集,差集)

    CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-30 @author: guaguastd @name: f ...

  6. List subList()的一个demo

    只要保证toIndex不大于size并且fromIndex不大于toIndex即可(谁会传一个负数的下标呢?) public List<E> subList(int fromIndex, ...

  7. OCEANIAERP对接-code盘点机并存储实时库存计划和方案的使用,实时库存,云清查方案

    1.     PDA手持设备按键说明 [Tab]键:使输入焦点在控件上切换. [ESC]键:弹出是否退出确认对话框,退出操作界面或程序. [OK]键:确认输入或选择,进入下一步操作. [C]键:删除键 ...

  8. Hsql中In没有1000的限制

    SELECT * FROM user , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...

  9. HTTP协议中返回代码302的情况

    http协议中,返回状态码302表示重定向. 这样的情况下,server返回的头部信息中会包括一个 Location 字段,内容是重定向到的url

  10. windows 10 install oracle 12c error:[ INS-30131 ]

    "[ INS-30131 ] the Initial Setup That Is Required to Run the Installation Program Validation Wa ...