当前位置:网站首页>notification是显示在手机状态栏的通知
notification是显示在手机状态栏的通知
2022-07-07 15:40:00 【XLMN】
notification是显示在手机状态栏的通知,手机状态栏位于手机最上方,一般显示手机当前网络状态,电池状态,实际等,notification所代表的是一种具有全局效果的通知
package com.example.check;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class MainActivity extends Activity {
static final int NOTIFICATION_ID = 0x123;
private NotificationManager nm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.notification);
//获取系统的NotificationManager服务
nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}
//为发送通知的按钮点击事件定义处理方法
public void send(View source) {
//创建一个启动其他activity的intent
Intent it = new Intent(MainActivity.this, OtherActivity.class);
PendingIntent pi = PendingIntent.getActivity(MainActivity.this, 0, it, 0);
Notification nf = new Notification.Builder(this)
//设置打开改通知,该通知自动消失
.setAutoCancel(true)
//设置显示在状态栏的通知提示信息
.setTicker("您有新的消息")
//设置通知的图标
.setSmallIcon(R.drawable.mia5)
//设置通知内容标题
.setContentTitle("一条新通知")
//设置通知内容
.setContentText("恭喜您,您被黄山学院,汉语言文学专业录取了")
//设置使用系统默认的声音,默认的led灯
.setDefaults(Notification.DEFAULT_SOUND)
//设置通知的自定义声音 .setSound(Uri.parse("android.resource://org.crazyit.ui/"+R.raw.msg))
// .setWhen(System.currentTimeMillis())
//设置通知将要启动程序的intent
.setContentIntent(pi)
.build();
//发送通知
nm.notify(NOTIFICATION_ID, nf);
}
//为删除通知的按钮的点击事件定义事件处理方法
public void del(View V) {
//取消通知
nm.cancel(NOTIFICATION_ID);
}
}
package com.example.check;
import android.app.Activity;
import android.os.Bundle;
public class OtherActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_other);
}
}
边栏推荐
- Skimage learning (3) -- adapt the gray filter to RGB images, separate colors by immunohistochemical staining, and filter the maximum value of the region
- 【可信计算】第十三次课:TPM扩展授权与密钥管理
- A tour of grpc:03 - proto serialization / deserialization
- Sator推出Web3游戏“Satorspace” ,并上线Huobi
- LeetCode 648(C#)
- 第3章业务功能开发(实现记住账号密码)
- Enum + Validation 的个人最佳实践 demo 分享
- 状态模式 - Unity(有限状态机)
- 本周小贴士#140:常量:安全习语
- MySQL usage notes 1
猜你喜欢
随机推荐
On Apache Doris Fe processing query SQL source code analysis
99% of users often make mistakes in power Bi cloud reports
How to implement safety practice in software development stage
跟奥巴马一起画方块(Lua)
数值 - number(Lua)
大笨钟(Lua)
如何在博客中添加Aplayer音乐播放器
本周小贴士#134:make_unique与私有构造函数
赋能智慧电力建设 | 麒麟信安高可用集群管理系统,保障用户关键业务连续性
Lex & yacc of Pisa proxy SQL parsing
centos7安装mysql笔记
【TPM2.0原理及应用指南】 12、13、14章
无法链接远程redis服务器(解决办法百分百)
Flask搭建api服务-生成API文档
使用Stace排除故障的5种简单方法
Skimage learning (2) -- RGB to grayscale, RGB to HSV, histogram matching
Sator a lancé le jeu web 3 "satorspace" et a lancé huobi
Number of exchanges in the 9th Blue Bridge Cup finals
麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会
【TPM2.0原理及应用指南】 1-3章