当前位置: 首页 > news >正文

Android 通知栏推送功能

Android 通知栏推送功能

Android 通知栏推送功能
让消息在用户的通知栏上显示,并且点击后跳转到指定的页面

MainActivity.Java


import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;import androidx.appcompat.app.AppCompatActivity;public class MainActivity extends AppCompatActivity {private static final String CHANNEL_ID = "my_channel_id";private static final String CHANNEL_NAME = "My Channel";private static final String CHANNEL_DESCRIPTION = "This is my notification channel";Bitmap bitmap = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button buttonSendNotification = findViewById(R.id.btn_show_normal);buttonSendNotification.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {int id = v.getId();if (id == R.id.btn_show_normal) {sendNotification();}}});}private void sendNotification() {bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.dzq);Intent intent = new Intent(this, SecondActivity.class);PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);notificationChannel.setDescription(CHANNEL_DESCRIPTION);notificationManager.createNotificationChannel(notificationChannel);}Notification notification = null;if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {notification = new Notification.Builder(this, CHANNEL_ID).setContentTitle("My Notification").setContentText("This is the body of my notification").setSmallIcon(R.drawable.ic_launcher_foreground).setLargeIcon(bitmap).setContentIntent(pendingIntent).setAutoCancel(true).build();}notificationManager.notify(0, notification);}
}

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context=".MainActivity"><Buttonandroid:id="@+id/btn_show_normal"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="显示普通的Notification" /></LinearLayout>

SecondActivity.Java

import android.os.Bundle;import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;/*** Created by Jay on 2015/9/28 0028.*/
public class SecondActivity extends AppCompatActivity {@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_second);}
}

activity_second.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".SecondActivity"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="阿三大苏打实打实"android:layout_centerInParent="true"/></RelativeLayout>

AndoirdManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.xxh.mynotification" ><uses-permission android:name="android.permission.FLASHLIGHT" /><uses-permission android:name="android.permission.POST_NOTIFICATIONS" /><uses-permission android:name="android.permission.VIBRATE" /><applicationandroid:allowBackup="true"android:icon="@mipmap/ic_lol_icon"android:label="@string/app_name"android:theme="@style/AppTheme" ><activityandroid:name=".MainActivity"android:label="@string/app_name"android:exported="true"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activity android:name=".SecondActivity"/></application></manifest>

R.drawable.ic_launcher_foreground.xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"android:width="108dp"android:height="108dp"android:viewportWidth="24"android:viewportHeight="24"android:tint="#000000"><group android:scaleX="0.6264"android:scaleY="0.6264"android:translateX="4.4832"android:translateY="4.4832"><pathandroid:fillColor="@android:color/white"android:pathData="M7,15H5.5v-4.5H4V9h3V15zM13.5,13.5h-3v-1h2c0.55,0 1,-0.45 1,-1V10c0,-0.55 -0.45,-1 -1,-1H9v1.5h3v1h-2c-0.55,0 -1,0.45 -1,1V15h4.5V13.5zM19.5,14v-4c0,-0.55 -0.45,-1 -1,-1H15v1.5h3v1h-2v1h2v1h-3V15h3.5C19.05,15 19.5,14.55 19.5,14z"/></group>
</vector>

相关文章:

Android 通知栏推送功能

Android 通知栏推送功能 Android 通知栏推送功能 让消息在用户的通知栏上显示&#xff0c;并且点击后跳转到指定的页面 MainActivity.Java import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import andro…...

【LVS】防火墙mark标记解决调度问题

实验环境是在之前部署DR模式集群的基础上做的&#xff0c;参考如下 部署DR模式集群 以http和https为例&#xff0c;当我们在webserver中同时开放80和443端口&#xff0c;那么默认控制是分开轮询的&#xff0c;就会出现了一个轮询错乱的问题&#xff1a; 当第一次访问80被轮询…...

算法笔记|Day20回溯算法II

算法笔记|Day20回溯算法II ☆☆☆☆☆leetcode 39. 组合总和题目分析代码 ☆☆☆☆☆leetcode 40.组合总和II题目分析代码 ☆☆☆☆☆leetcode 131.分割回文串题目分析代码 ☆☆☆☆☆leetcode 39. 组合总和 题目链接&#xff1a;leetcode 39. 组合总和 题目分析 本题采用回…...

Oracle认证1Z0-071线上考试注意事项

目录 一、前言二、回顾过往战绩第一次 裸考&#x1f412;第二次 背题库硬考&#xff01;&#x1f412;第三次 软件卡住&#xff0c;寄&#xff01;&#x1f648;第四次 汇总纠错&#xff0c;通过&#xff01;&#x1f31a; 三、考试流程四、考试注意事项1. 是否需要科学上网2. …...

【C++ 面试 - 基础题】每日 3 题(八)

✍个人博客&#xff1a;Pandaconda-CSDN博客 &#x1f4e3;专栏地址&#xff1a;http://t.csdnimg.cn/fYaBd &#x1f4da;专栏简介&#xff1a;在这个专栏中&#xff0c;我将会分享 C 面试中常见的面试题给大家~ ❤️如果有收获的话&#xff0c;欢迎点赞&#x1f44d;收藏&…...

影响LabVIEW工作效率的因素有哪些

影响LabVIEW工作效率的因素可以分为多个方面&#xff0c;涵盖硬件、软件、开发环境和编程习惯等。以下是一些常见的影响因素&#xff1a; 1. 硬件因素 处理器性能&#xff1a;处理器的速度和核心数量对LabVIEW程序的执行效率有很大影响。 内存大小&#xff1a;足够的内存可以保…...

linux 裸机.之SPV5210,dnw,usb,sdk,fastboot刷机(一)

linux 裸机.之SPV5210&#xff0c;dnw&#xff0c;usb&#xff0c;sdk&#xff0c;fastboot刷机&#xff08;一&#xff09;...

性能测试工具LoadRunner

前言&#x1f440;~ 上一章我们介绍了性能测试的一些基本概念&#xff0c;重要的是性能测试的各项指标&#xff0c;今天我们使用性能测试工具LoadRunner简单的完成一次性能测试 性能测试Load Runner LoadRunner是什么&#xff1f; LoadRunner安装 LoadRunner脚本录制 1.录…...

智能归来:深入探索人工智能回归模型的奥秘

人工智能之回归模型 1. 回归模型的数学基础1.1 回归分析的基本原理1.1.1 目标变量与预测变量的关系1.1.2 线性回归模型 1.2 矩阵形式的回归模型1.2.1 回归方程的矩阵表示1.2.2 矩阵运算的基本性质及其在回归分析中的应用 1.3 总结 2. 最小二乘法 (Ordinary Least Squares, OLS)…...

swift 中,对象() 和 对象.init() 的共同点和异同点

在阅读同事的代码时&#xff0c;不同人对对象的初始化方式是不一样的&#xff0c;例如存在一个对象AController, 有些人创建的方式如下&#xff1a; let controller AController()也有人创建的方式如下&#xff1a; let controller AController.init()下面来说明一下&#…...

Google安装JSON-handle扩展

JSON-hande下载地址&#xff1a; JSON-Handle 官网 - 打开json格式文件的浏览编辑器 1. 重命名扩展文件(crx)后缀 为 zip。 2. 解压zip成文件夹&#xff0c;保存到指定目录。 3. Google浏览器地址栏输入 “chrome://extensions/”回车。然后开启 开发者模式。 4. 点击“加载…...

剖析算法内部结构----------贪心算法

什么是贪心算法&#xff1f; 贪心算法&#xff08;Greedy Algorithm&#xff09;是一种在问题求解过程中&#xff0c;每一步都采取当前状态下最优&#xff08;即最有利&#xff09;的选择&#xff0c;从而希望导致最终的全局最优解的算法策略。 贪心算法的核心思想是做选择时&…...

uni-app开发微信小程序注意事项,不要用element-ui

前端扩展组件千万不要用element-ui&#xff0c;开发的时候不报错&#xff0c;发布的时候会报错无法发布。 可以用vant weapp【注意是weapp】 iView weapp 附上hbuilder官方文档 组件的概念 | uni-app官网 (dcloud.net.cn)...

Hibernate的检索策略(lazy、fetch、batch-size)

Hibernate的检索策略包括立即检索和延迟检索&#xff0c;可以在配置文件中通过对lazy、fetch、batch-size属性的设置来进行控制。一对多、多对多、多对一和一对一关系下的不同检索策略将影响对数据库访问的效率。 检索策略 立即检索&#xff0c;立即加载检索方法指定的对象延…...

算法训练(leetcode)第四十六天 | 110. 字符串接龙、105. 有向图的完全可达性、106. 岛屿的周长

刷题记录 *110. 字符串接龙105. 有向图的完全可达性邻接矩阵邻接表 106. 岛屿的周长深搜简化代码 *110. 字符串接龙 题目地址 使用广搜。 本题相当于求最短路径&#xff0c;因此使用广搜。如何应用广搜是一个难点&#xff0c;因为题目给的是字符串而非图的表示&#xff08;邻…...

自定义Mybatis-Plus分布式ID生成器(解决ID长度超过JavaScript整数安全范围问题)

自定义MyBatis-Plus分布式ID生成器&#xff08;解决ID长度超过JavaScript整数安全范围问题&#xff09; 版本 MyBatis-Plus 3.4.1 问题 MyBatis-Plus 默认生成的是 64bit 长整型&#xff0c;而 JS 的 Number 类型精度最高只有 53bit&#xff0c;如果以 Long 类型 ID 和前端…...

2024剪辑神器盘点:四大热门剪辑软件推荐!

亲爱的朋友们&#xff0c;想要制作出精彩短视频&#xff0c;却苦于找不到合适的剪辑工具&#xff1f;别担心&#xff0c;今天要向大家推荐几款剪辑软件&#xff0c;它们能帮助大家更好地完成视频创作&#xff01; 福昕视频剪辑 链接&#xff1a;www.pdf365.cn/foxit-clip/ 对…...

sql注入靶场sqli-labs常见sql注入漏洞详解

目录 sqli-labs-less1 1.less1普通解法 1.在url里面填写不同的值&#xff0c;返回的内容也不同&#xff0c;证明&#xff0c;数值是进入数据库进行比对了的&#xff08;可以被注入&#xff09; 2.判断最终执行的sql语句的后面还有内容吗&#xff0c;并且能够判断是字符型的拼接…...

[C++] 模板进阶:特化与编译链接全解析

文章目录 非类型模板类型形参非类型模板参数代码示例 **模板的特化**为什么要有模板的特化函数模板特化使用场景与示例函数模板特化的实现细节 类模板特化全特化示例 偏特化部分优化通过进一步限制模板参数进行特化偏特化为指针类型示例&#xff1a;偏特化为引用类型示例&#…...

oracle-备份

1、逻辑备份&#xff08;exp) /ljbb/oracle/o19c/bin/exp hr/hr tablesJOBS file/ljbb/bak/system.sql log/ljbb/bak/ststem.log query\where deptno30\ buffer100000000 hr/hr 用户/密码 tablesJOBS 表名&#xff1a;JOBS file/ljbb/bak/system.sql 备份文件路径 log/ljbb/ba…...

React 第五十五节 Router 中 useAsyncError的使用详解

前言 useAsyncError 是 React Router v6.4 引入的一个钩子&#xff0c;用于处理异步操作&#xff08;如数据加载&#xff09;中的错误。下面我将详细解释其用途并提供代码示例。 一、useAsyncError 用途 处理异步错误&#xff1a;捕获在 loader 或 action 中发生的异步错误替…...

地震勘探——干扰波识别、井中地震时距曲线特点

目录 干扰波识别反射波地震勘探的干扰波 井中地震时距曲线特点 干扰波识别 有效波&#xff1a;可以用来解决所提出的地质任务的波&#xff1b;干扰波&#xff1a;所有妨碍辨认、追踪有效波的其他波。 地震勘探中&#xff0c;有效波和干扰波是相对的。例如&#xff0c;在反射波…...

Cesium1.95中高性能加载1500个点

一、基本方式&#xff1a; 图标使用.png比.svg性能要好 <template><div id"cesiumContainer"></div><div class"toolbar"><button id"resetButton">重新生成点</button><span id"countDisplay&qu…...

PPT|230页| 制造集团企业供应链端到端的数字化解决方案:从需求到结算的全链路业务闭环构建

制造业采购供应链管理是企业运营的核心环节&#xff0c;供应链协同管理在供应链上下游企业之间建立紧密的合作关系&#xff0c;通过信息共享、资源整合、业务协同等方式&#xff0c;实现供应链的全面管理和优化&#xff0c;提高供应链的效率和透明度&#xff0c;降低供应链的成…...

cf2117E

原题链接&#xff1a;https://codeforces.com/contest/2117/problem/E 题目背景&#xff1a; 给定两个数组a,b&#xff0c;可以执行多次以下操作&#xff1a;选择 i (1 < i < n - 1)&#xff0c;并设置 或&#xff0c;也可以在执行上述操作前执行一次删除任意 和 。求…...

智能分布式爬虫的数据处理流水线优化:基于深度强化学习的数据质量控制

在数字化浪潮席卷全球的今天&#xff0c;数据已成为企业和研究机构的核心资产。智能分布式爬虫作为高效的数据采集工具&#xff0c;在大规模数据获取中发挥着关键作用。然而&#xff0c;传统的数据处理流水线在面对复杂多变的网络环境和海量异构数据时&#xff0c;常出现数据质…...

算法笔记2

1.字符串拼接最好用StringBuilder&#xff0c;不用String 2.创建List<>类型的数组并创建内存 List arr[] new ArrayList[26]; Arrays.setAll(arr, i -> new ArrayList<>()); 3.去掉首尾空格...

基于TurtleBot3在Gazebo地图实现机器人远程控制

1. TurtleBot3环境配置 # 下载TurtleBot3核心包 mkdir -p ~/catkin_ws/src cd ~/catkin_ws/src git clone -b noetic-devel https://github.com/ROBOTIS-GIT/turtlebot3.git git clone -b noetic https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git git clone -b noetic-dev…...

【SSH疑难排查】轻松解决新版OpenSSH连接旧服务器的“no matching...“系列算法协商失败问题

【SSH疑难排查】轻松解决新版OpenSSH连接旧服务器的"no matching..."系列算法协商失败问题 摘要&#xff1a; 近期&#xff0c;在使用较新版本的OpenSSH客户端连接老旧SSH服务器时&#xff0c;会遇到 "no matching key exchange method found"​, "n…...

Webpack性能优化:构建速度与体积优化策略

一、构建速度优化 1、​​升级Webpack和Node.js​​ ​​优化效果​​&#xff1a;Webpack 4比Webpack 3构建时间降低60%-98%。​​原因​​&#xff1a; V8引擎优化&#xff08;for of替代forEach、Map/Set替代Object&#xff09;。默认使用更快的md4哈希算法。AST直接从Loa…...