当前位置: 首页 > 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…...

Cursor实现用excel数据填充word模版的方法

cursor主页&#xff1a;https://www.cursor.com/ 任务目标&#xff1a;把excel格式的数据里的单元格&#xff0c;按照某一个固定模版填充到word中 文章目录 注意事项逐步生成程序1. 确定格式2. 调试程序 注意事项 直接给一个excel文件和最终呈现的word文件的示例&#xff0c;…...

vscode(仍待补充)

写于2025 6.9 主包将加入vscode这个更权威的圈子 vscode的基本使用 侧边栏 vscode还能连接ssh&#xff1f; debug时使用的launch文件 1.task.json {"tasks": [{"type": "cppbuild","label": "C/C: gcc.exe 生成活动文件"…...

vue3+vite项目中使用.env文件环境变量方法

vue3vite项目中使用.env文件环境变量方法 .env文件作用命名规则常用的配置项示例使用方法注意事项在vite.config.js文件中读取环境变量方法 .env文件作用 .env 文件用于定义环境变量&#xff0c;这些变量可以在项目中通过 import.meta.env 进行访问。Vite 会自动加载这些环境变…...

安宝特方案丨船舶智造的“AR+AI+作业标准化管理解决方案”(装配)

船舶制造装配管理现状&#xff1a;装配工作依赖人工经验&#xff0c;装配工人凭借长期实践积累的操作技巧完成零部件组装。企业通常制定了装配作业指导书&#xff0c;但在实际执行中&#xff0c;工人对指导书的理解和遵循程度参差不齐。 船舶装配过程中的挑战与需求 挑战 (1…...

[ACTF2020 新生赛]Include 1(php://filter伪协议)

题目 做法 启动靶机&#xff0c;点进去 点进去 查看URL&#xff0c;有 ?fileflag.php说明存在文件包含&#xff0c;原理是php://filter 协议 当它与包含函数结合时&#xff0c;php://filter流会被当作php文件执行。 用php://filter加编码&#xff0c;能让PHP把文件内容…...

PHP 8.5 即将发布:管道操作符、强力调试

前不久&#xff0c;PHP宣布了即将在 2025 年 11 月 20 日 正式发布的 PHP 8.5&#xff01;作为 PHP 语言的又一次重要迭代&#xff0c;PHP 8.5 承诺带来一系列旨在提升代码可读性、健壮性以及开发者效率的改进。而更令人兴奋的是&#xff0c;借助强大的本地开发环境 ServBay&am…...

密码学基础——SM4算法

博客主页&#xff1a;christine-rr-CSDN博客 ​​​​专栏主页&#xff1a;密码学 &#x1f4cc; 【今日更新】&#x1f4cc; 对称密码算法——SM4 目录 一、国密SM系列算法概述 二、SM4算法 2.1算法背景 2.2算法特点 2.3 基本部件 2.3.1 S盒 2.3.2 非线性变换 ​编辑…...

aardio 自动识别验证码输入

技术尝试 上周在发学习日志时有网友提议“在网页上识别验证码”&#xff0c;于是尝试整合图像识别与网页自动化技术&#xff0c;完成了这套模拟登录流程。核心思路是&#xff1a;截图验证码→OCR识别→自动填充表单→提交并验证结果。 代码在这里 import soImage; import we…...

2025-05-08-deepseek本地化部署

title: 2025-05-08-deepseek 本地化部署 tags: 深度学习 程序开发 2025-05-08-deepseek 本地化部署 参考博客 本地部署 DeepSeek&#xff1a;小白也能轻松搞定&#xff01; 如何给本地部署的 DeepSeek 投喂数据&#xff0c;让他更懂你 [实验目的]&#xff1a;理解系统架构与原…...

比特币:固若金汤的数字堡垒与它的四道防线

第一道防线&#xff1a;机密信函——无法破解的哈希加密 将每一笔比特币交易比作一封在堡垒内部传递的机密信函。 解释“哈希”&#xff08;Hashing&#xff09;就是一种军事级的加密术&#xff08;SHA-256&#xff09;&#xff0c;能将信函内容&#xff08;交易细节&#xf…...