当前位置:网站首页>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);
}
}
边栏推荐
- Lex & yacc of Pisa proxy SQL parsing
- 99%的人都不知道|私有化部署还永久免费的即时通讯软件!
- Rpcms method of obtaining articles under the specified classification
- 网络攻防复习篇
- LeetCode 648(C#)
- 【网络攻防原理与技术】第5章:拒绝服务攻击
- PLC:自动纠正数据集噪声,来洗洗数据集吧 | ICLR 2021 Spotlight
- The server is completely broken and cannot be repaired. How to use backup to restore it into a virtual machine without damage?
- 如何在软件研发阶段落地安全实践
- 第3章业务功能开发(实现记住账号密码)
猜你喜欢
随机推荐
User defined view essential knowledge, Android R & D post must ask 30+ advanced interview questions
Flash build API service
rpcms获取指定分类下的文章的方法
[Seaborn] implementation of combined charts and multi subgraphs
Reflections on "product managers must read: five classic innovative thinking models"
Jenkins发布uniapp开发的H5遇到的问题
本周小贴士131:特殊成员函数和`= default`
【网络攻防原理与技术】第5章:拒绝服务攻击
Solid function learning
Smart logistics platform: make overseas warehouses smarter
【饭谈】Web3.0到来后,测试人员该何去何从?(十条预言和建议)
Solidity 开发环境搭建
Biped robot controlled by Arduino
【黄啊码】为什么我建议您选择go,而不选择php?
自定义View必备知识,Android研发岗必问30+道高级面试题
L1-028 判断素数(Lua)
L1-019 谁先倒(Lua)
[image sensor] correlated double sampling CDs
Flash build API Service - generate API documents
如何在软件研发阶段落地安全实践









