notification android原生消息通知代码详解
来源:互联网 发布:编程语言的3个属性 编辑:程序博客网 时间:2024/06/05 14:17
package us.guaju.notification;import android.app.Activity;import android.app.Notification;import android.app.NotificationManager;import android.app.PendingIntent;import android.content.Context;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class MainActivity extends Activity {private static final int TAG = 8888;protected static final int REQUESTCODE = 0;private Button send_notification, clear;private NotificationManager notificationManager;private Notification notificastion;private int count = 0;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);send_notification = (Button) findViewById(R.id.send_notification);clear = (Button) findViewById(R.id.clear);notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);// 点击button发送通知send_notification.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {Notification.Builder builder = new Notification.Builder(MainActivity.this);builder.setContentTitle("我是通知");builder.setContentText("我是通知内容");builder.setContentInfo("我是通知附加信息" + count);// 创建一个普通的意图,为下方的pendingIntent做准备Intent intent = new Intent();intent.setAction(Intent.ACTION_DIAL);// 创建pendingIntent 传入上文定制好的意图PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, REQUESTCODE, intent,Intent.FLAG_ACTIVITY_NEW_TASK);// 如此点击完成后会跳转到拨号界面builder.setContentIntent(pendingIntent);builder.setSmallIcon(R.drawable.ic_launcher);notificastion = builder.getNotification();count++;notificationManager.notify(TAG, notificastion);}});clear.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {notificationManager.cancelAll();}});}}如果有不懂的可以直接查看developer.android.com去学习。此篇文章基本能满足日常需要
2 0
- notification android原生消息通知代码详解
- Android 消息通知-Notification
- Android 消息通知-Notification
- Android 原生通知Notification 写法
- Notification---Android Notification通知详解
- Android Notification通知详解
- Android Notification通知详解
- Android Notification通知详解
- Android Notification通知详解
- Android 通知Notification详解
- Android Notification通知详解
- Android Notification通知详解
- Android Notification通知详解
- Android Notification通知详解
- Android Notification通知详解
- Android Notification通知详解
- Android Notification通知详解
- Android Notification通知详解
- ASP.NET视频知识总结 chapter12
- Scala(三)之“控制结构”
- POJ 1252 Euro Efficiency(完全背包变型)
- Vim中插入等差数值
- 空指针与野指针
- notification android原生消息通知代码详解
- Session与Cookie的比较
- [操作系统] 复习一
- 【Java学习】使用泛型和反射 创建通用的数据库查询方法
- 【Linux网络编程】TCP网络编程中connect()、listen()和accept()三者之间的关系
- java nio学习之 socket+nio 通信
- 安卓面试题大全,有答案哦
- BASE64
- javascript双等号引起的类型转换,js隐性类型转换步骤