Notification
来源:互联网 发布:sweetalert.js 编辑:程序博客网 时间:2024/06/05 10:23
权限设置:
<uses-permission android:name="android.permission.FLASHLIGHT"/>//闪光灯 <uses-permission android:name="android.permission.VIBRATE"/>//震动
package com.example.notification;import android.R.integer;import android.app.Activity;import android.app.Notification;import android.app.NotificationManager;import android.app.PendingIntent;import android.app.Notification.*;import android.content.Context;import android.content.Intent;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class MainActivity extends Activity {private Button button1;private Button button2;NotificationManager manager;int notification_id; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); manager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); button1=(Button) findViewById(R.id.button1); button1.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubnotification();}}); button2=(Button) findViewById(R.id.button2); button2.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubcancel();}}); }//构造notofication并发送到通知栏 private void notification(){ Intent intent =new Intent(this,MainActivity.class); PendingIntent pIntent=PendingIntent.getActivity(this,0,intent,0); Builder builder=new Notification.Builder(this); builder.setSmallIcon(R.drawable.ic_launcher);//设置图标 builder.setTicker("Hello");//手机状态栏的提示 builder.setWhen(System.currentTimeMillis());//设置时间 builder.setContentTitle("通知栏通知");//设置标题 builder.setContentText("我来自Notification");//设置通知内容 builder.setContentIntent(pIntent);//点击后的意图// builder.setDefaults(Notification.DEFAULT_SOUND);//声音// builder.setDefaults(Notification.DEFAULT_LIGHTS);//闪光灯// builder.setDefaults(Notification.DEFAULT_VIBRATE);//震动效果 builder.setDefaults(Notification.DEFAULT_ALL);//三种效果全有 //Notification notification=builder.build();//4.1以上版本用 Notification notification=builder.getNotification();//4.1以下版本用 manager.notify(notification_id,notification); } //取消通知栏通知 private void cancel(){ manager.cancel(notification_id); }
0 0
- Notification
- Notification
- Notification
- Notification
- notification
- Notification
- Notification
- Notification
- Notification
- Notification
- Notification
- Notification
- Notification
- notification
- Notification
- Notification
- Notification
- Notification
- C#转义 Console.WriteLine("{0}, {{{1}}}", "ab", "xyz");
- 2016 07 17所学
- gnuradio+USRP实现OpenBTS 5.0安装
- 码神第三天学习(加作业)
- 深度学习与自然语言处理(7)_斯坦福cs224d 语言模型,RNN,LSTM与GRU
- Notification
- 冯诺依曼工作方式的基本特点是____
- Linux GCC常用命令
- Leetcode-sort-list
- text().toInt(&ok)获取标签控件字符串的方法
- 浅谈essay、paper和dissertation的区别
- 2016年7月17日学习 scratch 小兔子偷胡萝卜的故事
- C++中虚函数表存储位置浅析
- Docker Universal Control Plane(UCP)——提供企业级的容器云的解决方案