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 通知栏推送功能 让消息在用户的通知栏上显示,并且点击后跳转到指定的页面 MainActivity.Java import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import andro…...
【LVS】防火墙mark标记解决调度问题
实验环境是在之前部署DR模式集群的基础上做的,参考如下 部署DR模式集群 以http和https为例,当我们在webserver中同时开放80和443端口,那么默认控制是分开轮询的,就会出现了一个轮询错乱的问题: 当第一次访问80被轮询…...
算法笔记|Day20回溯算法II
算法笔记|Day20回溯算法II ☆☆☆☆☆leetcode 39. 组合总和题目分析代码 ☆☆☆☆☆leetcode 40.组合总和II题目分析代码 ☆☆☆☆☆leetcode 131.分割回文串题目分析代码 ☆☆☆☆☆leetcode 39. 组合总和 题目链接:leetcode 39. 组合总和 题目分析 本题采用回…...
Oracle认证1Z0-071线上考试注意事项
目录 一、前言二、回顾过往战绩第一次 裸考🐒第二次 背题库硬考!🐒第三次 软件卡住,寄!🙈第四次 汇总纠错,通过!🌚 三、考试流程四、考试注意事项1. 是否需要科学上网2. …...
【C++ 面试 - 基础题】每日 3 题(八)
✍个人博客:Pandaconda-CSDN博客 📣专栏地址:http://t.csdnimg.cn/fYaBd 📚专栏简介:在这个专栏中,我将会分享 C 面试中常见的面试题给大家~ ❤️如果有收获的话,欢迎点赞👍收藏&…...
影响LabVIEW工作效率的因素有哪些
影响LabVIEW工作效率的因素可以分为多个方面,涵盖硬件、软件、开发环境和编程习惯等。以下是一些常见的影响因素: 1. 硬件因素 处理器性能:处理器的速度和核心数量对LabVIEW程序的执行效率有很大影响。 内存大小:足够的内存可以保…...
linux 裸机.之SPV5210,dnw,usb,sdk,fastboot刷机(一)
linux 裸机.之SPV5210,dnw,usb,sdk,fastboot刷机(一)...
性能测试工具LoadRunner
前言👀~ 上一章我们介绍了性能测试的一些基本概念,重要的是性能测试的各项指标,今天我们使用性能测试工具LoadRunner简单的完成一次性能测试 性能测试Load Runner LoadRunner是什么? 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() 的共同点和异同点
在阅读同事的代码时,不同人对对象的初始化方式是不一样的,例如存在一个对象AController, 有些人创建的方式如下: let controller AController()也有人创建的方式如下: let controller AController.init()下面来说明一下&#…...
Google安装JSON-handle扩展
JSON-hande下载地址: JSON-Handle 官网 - 打开json格式文件的浏览编辑器 1. 重命名扩展文件(crx)后缀 为 zip。 2. 解压zip成文件夹,保存到指定目录。 3. Google浏览器地址栏输入 “chrome://extensions/”回车。然后开启 开发者模式。 4. 点击“加载…...
剖析算法内部结构----------贪心算法
什么是贪心算法? 贪心算法(Greedy Algorithm)是一种在问题求解过程中,每一步都采取当前状态下最优(即最有利)的选择,从而希望导致最终的全局最优解的算法策略。 贪心算法的核心思想是做选择时&…...
uni-app开发微信小程序注意事项,不要用element-ui
前端扩展组件千万不要用element-ui,开发的时候不报错,发布的时候会报错无法发布。 可以用vant weapp【注意是weapp】 iView weapp 附上hbuilder官方文档 组件的概念 | uni-app官网 (dcloud.net.cn)...
Hibernate的检索策略(lazy、fetch、batch-size)
Hibernate的检索策略包括立即检索和延迟检索,可以在配置文件中通过对lazy、fetch、batch-size属性的设置来进行控制。一对多、多对多、多对一和一对一关系下的不同检索策略将影响对数据库访问的效率。 检索策略 立即检索,立即加载检索方法指定的对象延…...
算法训练(leetcode)第四十六天 | 110. 字符串接龙、105. 有向图的完全可达性、106. 岛屿的周长
刷题记录 *110. 字符串接龙105. 有向图的完全可达性邻接矩阵邻接表 106. 岛屿的周长深搜简化代码 *110. 字符串接龙 题目地址 使用广搜。 本题相当于求最短路径,因此使用广搜。如何应用广搜是一个难点,因为题目给的是字符串而非图的表示(邻…...
自定义Mybatis-Plus分布式ID生成器(解决ID长度超过JavaScript整数安全范围问题)
自定义MyBatis-Plus分布式ID生成器(解决ID长度超过JavaScript整数安全范围问题) 版本 MyBatis-Plus 3.4.1 问题 MyBatis-Plus 默认生成的是 64bit 长整型,而 JS 的 Number 类型精度最高只有 53bit,如果以 Long 类型 ID 和前端…...
2024剪辑神器盘点:四大热门剪辑软件推荐!
亲爱的朋友们,想要制作出精彩短视频,却苦于找不到合适的剪辑工具?别担心,今天要向大家推荐几款剪辑软件,它们能帮助大家更好地完成视频创作! 福昕视频剪辑 链接:www.pdf365.cn/foxit-clip/ 对…...
sql注入靶场sqli-labs常见sql注入漏洞详解
目录 sqli-labs-less1 1.less1普通解法 1.在url里面填写不同的值,返回的内容也不同,证明,数值是进入数据库进行比对了的(可以被注入) 2.判断最终执行的sql语句的后面还有内容吗,并且能够判断是字符型的拼接…...
[C++] 模板进阶:特化与编译链接全解析
文章目录 非类型模板类型形参非类型模板参数代码示例 **模板的特化**为什么要有模板的特化函数模板特化使用场景与示例函数模板特化的实现细节 类模板特化全特化示例 偏特化部分优化通过进一步限制模板参数进行特化偏特化为指针类型示例:偏特化为引用类型示例&#…...
oracle-备份
1、逻辑备份(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 表名:JOBS file/ljbb/bak/system.sql 备份文件路径 log/ljbb/ba…...
Cursor实现用excel数据填充word模版的方法
cursor主页:https://www.cursor.com/ 任务目标:把excel格式的数据里的单元格,按照某一个固定模版填充到word中 文章目录 注意事项逐步生成程序1. 确定格式2. 调试程序 注意事项 直接给一个excel文件和最终呈现的word文件的示例,…...
vscode(仍待补充)
写于2025 6.9 主包将加入vscode这个更权威的圈子 vscode的基本使用 侧边栏 vscode还能连接ssh? debug时使用的launch文件 1.task.json {"tasks": [{"type": "cppbuild","label": "C/C: gcc.exe 生成活动文件"…...
vue3+vite项目中使用.env文件环境变量方法
vue3vite项目中使用.env文件环境变量方法 .env文件作用命名规则常用的配置项示例使用方法注意事项在vite.config.js文件中读取环境变量方法 .env文件作用 .env 文件用于定义环境变量,这些变量可以在项目中通过 import.meta.env 进行访问。Vite 会自动加载这些环境变…...
安宝特方案丨船舶智造的“AR+AI+作业标准化管理解决方案”(装配)
船舶制造装配管理现状:装配工作依赖人工经验,装配工人凭借长期实践积累的操作技巧完成零部件组装。企业通常制定了装配作业指导书,但在实际执行中,工人对指导书的理解和遵循程度参差不齐。 船舶装配过程中的挑战与需求 挑战 (1…...
[ACTF2020 新生赛]Include 1(php://filter伪协议)
题目 做法 启动靶机,点进去 点进去 查看URL,有 ?fileflag.php说明存在文件包含,原理是php://filter 协议 当它与包含函数结合时,php://filter流会被当作php文件执行。 用php://filter加编码,能让PHP把文件内容…...
PHP 8.5 即将发布:管道操作符、强力调试
前不久,PHP宣布了即将在 2025 年 11 月 20 日 正式发布的 PHP 8.5!作为 PHP 语言的又一次重要迭代,PHP 8.5 承诺带来一系列旨在提升代码可读性、健壮性以及开发者效率的改进。而更令人兴奋的是,借助强大的本地开发环境 ServBay&am…...
密码学基础——SM4算法
博客主页:christine-rr-CSDN博客 专栏主页:密码学 📌 【今日更新】📌 对称密码算法——SM4 目录 一、国密SM系列算法概述 二、SM4算法 2.1算法背景 2.2算法特点 2.3 基本部件 2.3.1 S盒 2.3.2 非线性变换 编辑…...
aardio 自动识别验证码输入
技术尝试 上周在发学习日志时有网友提议“在网页上识别验证码”,于是尝试整合图像识别与网页自动化技术,完成了这套模拟登录流程。核心思路是:截图验证码→OCR识别→自动填充表单→提交并验证结果。 代码在这里 import soImage; import we…...
2025-05-08-deepseek本地化部署
title: 2025-05-08-deepseek 本地化部署 tags: 深度学习 程序开发 2025-05-08-deepseek 本地化部署 参考博客 本地部署 DeepSeek:小白也能轻松搞定! 如何给本地部署的 DeepSeek 投喂数据,让他更懂你 [实验目的]:理解系统架构与原…...
比特币:固若金汤的数字堡垒与它的四道防线
第一道防线:机密信函——无法破解的哈希加密 将每一笔比特币交易比作一封在堡垒内部传递的机密信函。 解释“哈希”(Hashing)就是一种军事级的加密术(SHA-256),能将信函内容(交易细节…...
