当前位置:网站首页>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);
}
}
边栏推荐
- [fan Tan] those stories that seem to be thinking of the company but are actually very selfish (I: building wheels)
- 【可信计算】第十二次课:TPM授权与会话
- Matplotlib绘图界面设置
- LeetCode 312. Poke balloon daily
- Sator推出Web3遊戲“Satorspace” ,並上線Huobi
- L1-025 正整数A+B(Lua)
- 管理VDI的几个最佳实践
- MySQL implements the query of merging two fields into one field
- 简单的loading动画
- 第3章业务功能开发(实现记住账号密码)
猜你喜欢

User defined view essential knowledge, Android R & D post must ask 30+ advanced interview questions

Shallow understanding Net core routing

简单的loading动画
![[video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial](/img/14/4e7ebfb1ed5b99f8377af9d17d2177.jpg)
[video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial

《世界粮食安全和营养状况》报告发布:2021年全球饥饿人口增至8.28亿

Skimage learning (2) -- RGB to grayscale, RGB to HSV, histogram matching

SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名

鲲鹏开发者峰会2022 | 麒麟信安携手鲲鹏共筑计算产业新生态

How to choose the appropriate automated testing tools?

自定义View必备知识,Android研发岗必问30+道高级面试题
随机推荐
【信息安全法律法規】複習篇
Solid function learning
Solidity 开发环境搭建
命令模式 - Unity
【网络攻防原理与技术】第6章:特洛伊木马
字符串 - string(Lua)
策略模式 - Unity
Number of exchanges in the 9th Blue Bridge Cup finals
[Seaborn] implementation of combined charts and multi subgraphs
【TPM2.0原理及应用指南】 9、10、11章
责任链模式 - Unity
LeetCode 648(C#)
With the latest Alibaba P7 technology system, mom doesn't have to worry about me looking for a job anymore
AI来搞财富分配比人更公平?来自DeepMind的多人博弈游戏研究
第3章业务功能开发(安全退出)
简单的loading动画
第二十四届中国科协湖南组委会调研课题组一行莅临麒麟信安调研考察
How to choose the appropriate automated testing tools?
[Seaborn] combination chart: pairplot and jointplot
Skimage learning (1)