当前位置:网站首页>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);
}
}
边栏推荐
- 第二十四届中国科协湖南组委会调研课题组一行莅临麒麟信安调研考察
- Sator推出Web3游戏“Satorspace” ,并上线Huobi
- LeetCode 497(C#)
- 【网络攻防原理与技术】第7章:口令攻击技术 第8章:网络监听技术
- 【源码解读】| LiveListenerBus源码解读
- DevOps 的运营和商业利益指南
- Devops' operational and commercial benefits Guide
- 命令模式 - Unity
- [source code interpretation] | source code interpretation of livelistenerbus
- Nerf: the ultimate replacement for deepfake?
猜你喜欢

状态模式 - Unity(有限状态机)

第3章业务功能开发(用户访问项目)

【TPM2.0原理及应用指南】 9、10、11章

Matplotlib绘图界面设置

Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind

测试用例管理工具推荐

【可信计算】第十二次课:TPM授权与会话

Sator推出Web3遊戲“Satorspace” ,並上線Huobi

让保险更“保险”!麒麟信安一云多芯云桌面中标中国人寿, 助力金融保险信息技术创新发展

【视频/音频数据处理】上海道宁为您带来Elecard下载、试用、教程
随机推荐
LeetCode 648(C#)
Skimage learning (2) -- RGB to grayscale, RGB to HSV, histogram matching
[source code interpretation] | source code interpretation of livelistenerbus
状态模式 - Unity(有限状态机)
MySQL usage notes 1
麒麟信安云平台全新升级!
Matplotlib绘制三维图形
rpcms获取指定分类下的文章的方法
【TPM2.0原理及应用指南】 1-3章
How to add aplayer music player in blog
字符串 - string(Lua)
Solid function learning
PLC:自动纠正数据集噪声,来洗洗数据集吧 | ICLR 2021 Spotlight
第2章搭建CRM项目开发环境(搭建开发环境)
科普达人丨一文弄懂什么是云计算?
Solidity 开发环境搭建
责任链模式 - Unity
Sator launched Web3 game "satorspace" and launched hoobi
LeetCode刷题day49
本周小贴士#136:无序容器