Notification简介

Notification位于手机饿最上面,用于显示手机的各种信息,包括网络状态,电池状态,时间等。

属性方法介绍

代码示例

package peng.liu.test;import android.app.Activity;import android.app.Notification;import android.app.NotificationManager;import android.app.PendingIntent;import android.app.TabActivity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.TabHost;public class MainActivity extends Activity {    static final int NOTIFICATION__ID = 0X123;    NotificationManager nm;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);    }    public void send(View view){        Intent intent = new Intent(MainActivity.this,MainActivity2.class);        PendingIntent pi = PendingIntent.getActivity(MainActivity.this,0,intent,0);        Notification notification = new Notification.Builder(this).setAutoCancel(true)                .setTicker("新消息")                .setSmallIcon(R.drawable.ic_launcher)                .setContentTitle("new message")                .setContentText("hello world")                .setDefaults(Notification.DEFAULT_SOUND|Notification.DEFAULT_LIGHTS)                .setWhen(System.currentTimeMillis())                .setContentIntent(pi)                .build();        nm.notify(NOTIFICATION__ID,notification);    }    public void dev(View view){        nm.cancel(NOTIFICATION__ID);    }}
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" >    <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button" android:onClick="send"/>    <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button2" android:onClick="dev"/></LinearLayout>

更多相关文章

  1. 阅读《Android(安卓)从入门到精通》(17)——进度条
  2. Android面试题集(陆续更新中)
  3. Android使用Intent启动Service的Intent必须是显式的
  4. Android(安卓)输入键盘弹出隐藏监听
  5. 修正android cocos2dx项目当点击属性时提示错误的问题
  6. Android中的android.provider.Settings.System系统属性设定
  7. android 上层应用如何监听 sdcard的插拔事件
  8. 创建ListView的基本步骤
  9. Android沉浸式标题栏状态栏字体颜色修改(小米和魅族以及Android6.

随机推荐

  1. ViewBinding的简单使用
  2. Android广播接收器BroadcastReceiver——
  3. Android(安卓)四大组件:这是一份全面 & 详
  4. android 传感器的使用
  5. 【Android自学笔记】Android中的Log小技
  6. Android短信发送流程之长短信发送(原)
  7. Android DownloadManager下载进度查询(系
  8. Android 常用的提示框,输入框,弹窗
  9. Android(安卓)添加系统设置属性的实现及
  10. android phone模块 4.2平台和4.4平台上的