当前位置:网站首页>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);
}
}
边栏推荐
猜你喜欢
使用popupwindow創建对话框风格的窗口
Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind
Sator launched Web3 game "satorspace" and launched hoobi
第2章搭建CRM项目开发环境(数据库设计)
【网络攻防原理与技术】第6章:特洛伊木马
Dateticket and timeticket, functions and usage of date and time selectors
textSwitch文本切换器的功能和用法
Numberpick的功能和用法
DatePickerDialog和trimepickerDialog
mysql官网下载:Linux的mysql8.x版本(图文详解)
随机推荐
The top of slashdata developer tool is up to you!!!
Audio Device Strategy 音频设备输出、输入 选择 基于7.0 代码
MRS离线数据分析:通过Flink作业处理OBS数据
【TPM2.0原理及应用指南】 9、10、11章
MySQL implements the query of merging two fields into one field
DevOps 的运营和商业利益指南
Rpcms method of obtaining articles under the specified classification
DNS 系列(一):为什么更新了 DNS 记录不生效?
rpcms获取指定分类下的文章的方法
阿富汗临时政府安全部队对极端组织“伊斯兰国”一处藏匿点展开军事行动
使用popupwindow創建对话框风格的窗口
Flask搭建api服务
99% of users often make mistakes in power Bi cloud reports
Devops' operational and commercial benefits Guide
【可信计算】第十一次课:TPM密码资源管理(三) NV索引与PCR
第3章业务功能开发(用户访问项目)
Mysql 索引命中级别分析
自定义View必备知识,Android研发岗必问30+道高级面试题
如何在软件研发阶段落地安全实践
Lex & yacc of Pisa proxy SQL parsing