当前位置:网站首页>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);
}
}
边栏推荐
- Flash build API service
- 责任链模式 - Unity
- Skimage learning (3) -- adapt the gray filter to RGB images, separate colors by immunohistochemical staining, and filter the maximum value of the region
- PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
- 第3章业务功能开发(实现记住账号密码)
- Several best practices for managing VDI
- Flask搭建api服务-SQL配置文件
- Repair method of firewall system crash and file loss, material cost 0 yuan
- 【网络攻防原理与技术】第3章:网络侦察技术
- Solid function learning
猜你喜欢
随机推荐
LeetCode 648(C#)
Problems encountered in Jenkins' release of H5 developed by uniapp
L1-027 出租(Lua)
The server is completely broken and cannot be repaired. How to use backup to restore it into a virtual machine without damage?
【可信计算】第十次课:TPM密码资源管理(二)
Smart logistics platform: make overseas warehouses smarter
User defined view essential knowledge, Android R & D post must ask 30+ advanced interview questions
Jenkins发布uniapp开发的H5遇到的问题
[Seaborn] implementation of combined charts and multi subgraphs
【源码解读】| LiveListenerBus源码解读
数值 - number(Lua)
科普达人丨一文弄懂什么是云计算?
The computer cannot add a domain, and the Ping domain name is displayed as the public IP. What is the problem? How to solve it?
redis主从、哨兵主备切换搭建一步一步图解实现
L1-019 谁先倒(Lua)
【饭谈】那些看似为公司着想,实际却很自私的故事 (一:造轮子)
mysql实现两个字段合并成一个字段查询
本周小贴士#140:常量:安全习语
【网络攻防原理与技术】第5章:拒绝服务攻击
麒麟信安云平台全新升级!