当前位置:网站首页>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);
}
}
边栏推荐
- First in China! Todesk integrates RTC technology into remote desktop, with clearer image quality and smoother operation
- datepicket和timepicket,日期、时间选择器的功能和用法
- How to mount the original data disk without damage after the reinstallation of proxmox ve?
- 简单的loading动画
- Enum + Validation 的个人最佳实践 demo 分享
- Flash build API service
- 第3章业务功能开发(实现记住账号密码)
- Functions and usage of viewswitch
- Audio Device Strategy 音频设备输出、输入 选择 基于7.0 代码
- notification是显示在手机状态栏的通知
猜你喜欢
随机推荐
L1-028 判断素数(Lua)
【可信计算】第十一次课:TPM密码资源管理(三) NV索引与PCR
MRS离线数据分析:通过Flink作业处理OBS数据
自定义View必备知识,Android研发岗必问30+道高级面试题
简单的loading动画
本周小贴士#141:注意隐式转换到bool
国内首创!Todesk将RTC技术融入远程桌面,画质更清晰操作更流畅
Sator推出Web3游戏“Satorspace” ,并上线Huobi
With the latest Alibaba P7 technology system, mom doesn't have to worry about me looking for a job anymore
Solid function learning
Smart logistics platform: make overseas warehouses smarter
【网络攻防原理与技术】第6章:特洛伊木马
跟奥巴马一起画方块(Lua)
状态模式 - Unity(有限状态机)
Mysql 索引命中级别分析
【源码解读】| LiveListenerBus源码解读
alertDialog創建对话框
LeetCode刷题day49
How to implement safety practice in software development stage
请将磁盘插入“U盘(H)“的情况&无法访问 磁盘结构损坏且无法读取