当前位置:网站首页>Notification is the notification displayed in the status bar of the phone
Notification is the notification displayed in the status bar of the phone
2022-07-07 17:37:00 【XLMN】
notification Is the notification displayed in the phone status bar , The mobile status bar is located at the top of the mobile , Generally, it displays the current network status of the mobile phone , Battery status , Actual, etc ,notification It represents a kind of notification with global effect
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);
// Get system's NotificationManager service
nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}
// Define the processing method for the button click event that sends the notification
public void send(View source) {
// Create one to start other activity Of intent
Intent it = new Intent(MainActivity.this, OtherActivity.class);
PendingIntent pi = PendingIntent.getActivity(MainActivity.this, 0, it, 0);
Notification nf = new Notification.Builder(this)
// Set open change notification , The notification disappears automatically
.setAutoCancel(true)
// Set the notification prompt displayed in the status bar
.setTicker(" You have new news ")
// Set the icon for the notification
.setSmallIcon(R.drawable.mia5)
// Set the title of the notification
.setContentTitle(" A new notice ")
// Set notification content
.setContentText(" Congratulations , You were accepted by Huangshan University , The major of Chinese language and literature was admitted ")
// Set to use the system default sound , default led The lamp
.setDefaults(Notification.DEFAULT_SOUND)
// Set a custom sound for notifications .setSound(Uri.parse("android.resource://org.crazyit.ui/"+R.raw.msg))
// .setWhen(System.currentTimeMillis())
// Set the notification that the program is about to start intent
.setContentIntent(pi)
.build();
// Sending notice
nm.notify(NOTIFICATION_ID, nf);
}
// Define the event handling method for the click event of the button to delete the notification
public void del(View V) {
// Notice of cancellation
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);
}
}
边栏推荐
猜你喜欢

策略模式 - Unity

麒麟信安加入宁夏商用密码协会

mysql官网下载:Linux的mysql8.x版本(图文详解)

麒麟信安操作系统衍生产品解决方案 | 存储多路径管理系统,有效提高数据传输可靠性

Siggraph 2022 best technical paper award comes out! Chen Baoquan team of Peking University was nominated for honorary nomination

LeetCode刷题day49

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

网络攻防复习篇

How to choose the appropriate automated testing tools?

Dateticket and timeticket, functions and usage of date and time selectors
随机推荐
【TPM2.0原理及应用指南】 9、10、11章
专精特新软件开发类企业实力指数发布,麒麟信安荣誉登榜
到底有多二(Lua)
国内首创!Todesk将RTC技术融入远程桌面,画质更清晰操作更流畅
Function and usage of textswitch text switcher
TabHOST 选项卡的功能和用法
A tour of grpc:03 - proto serialization / deserialization
Functions and usage of imageswitch
MySQL implements the query of merging two fields into one field
Flash build API Service - generate API documents
麒麟信安中标国网新一代调度项目!
阿富汗临时政府安全部队对极端组织“伊斯兰国”一处藏匿点展开军事行动
L1-027 出租(Lua)
Solid function learning
How to mount the original data disk without damage after the reinstallation of proxmox ve?
[fan Tan] those stories that seem to be thinking of the company but are actually very selfish (I: building wheels)
What is cloud computing?
【分布式理论】(一)分布式事务
网络攻防复习篇
rpcms获取指定分类下的文章的方法