当前位置:网站首页>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);
}
}
边栏推荐
猜你喜欢

【TPM2.0原理及应用指南】 16、17、18章

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

第3章业务功能开发(实现记住账号密码)

DevOps 的运营和商业利益指南

Leetcode brush questions day49

Sator a lancé le jeu web 3 "satorspace" et a lancé huobi

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

Sator推出Web3游戏“Satorspace” ,并上线Huobi

Mrs offline data analysis: process OBS data through Flink job

The top of slashdata developer tool is up to you!!!
随机推荐
【分布式理论】(一)分布式事务
[video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial
MRS离线数据分析:通过Flink作业处理OBS数据
[Fantan] how to design a test platform?
管理VDI的几个最佳实践
PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
Mrs offline data analysis: process OBS data through Flink job
LeetCode 515(C#)
99%的人都不知道|私有化部署还永久免费的即时通讯软件!
L1-028 判断素数(Lua)
What is cloud computing?
大笨钟(Lua)
【网络攻防原理与技术】第5章:拒绝服务攻击
第二十四届中国科协湖南组委会调研课题组一行莅临麒麟信安调研考察
【分布式理论】(二)分布式存储
First in China! Todesk integrates RTC technology into remote desktop, with clearer image quality and smoother operation
请将磁盘插入“U盘(H)“的情况&无法访问 磁盘结构损坏且无法读取
【可信计算】第十一次课:TPM密码资源管理(三) NV索引与PCR
Nerf: the ultimate replacement for deepfake?
本周小贴士#141:注意隐式转换到bool