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

Android前台服务和通知

前台服务

Android 13及以上系统需要动态获取通知权限。

//android 13及以上系统动态获取通知权限
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {checkPostNotificationPermission();
}
private void checkPostNotificationPermission() {if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS)!= PackageManager.PERMISSION_GRANTED) {ActivityCompat.requestPermissions((Activity) this, new String[]{Manifest.permission.POST_NOTIFICATIONS}, 200);} else if (manager != null) {//通知ID设置(您可以使用任何您想要的ID,相同ID通知只会显示一个)。manager.notify(2, builder.build());}
}@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {super.onRequestPermissionsResult(requestCode, permissions, grantResults);if (requestCode == 200) {if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {//允许了通知权限} else {Toast.makeText(this, "您拒绝了通知权限", Toast.LENGTH_SHORT).show();}}
}

别忘记添加通知权限

<!--发布通知权限-->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

开启前台服务需要添加前台服务权限

<!--前台服务权限-->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

通知震动需要添加震动权限

<!--振动器权限-->
<uses-permission android:name="android.permission.VIBRATE" />

前台服务代码

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.IBinder;import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;import com.example.javatest.MainActivity;
import com.example.javatest.R;/*** created by cwj on 2023-10-19* Description: 前台服务*/
public class ForegroundService extends Service {@Overridepublic void onCreate() {super.onCreate();if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {CharSequence name = getString(R.string.app_name);int importance = NotificationManager.IMPORTANCE_DEFAULT;NotificationChannel channel = new NotificationChannel("CHANNEL_ID", name, importance);channel.setDescription("前台服务守护进程");NotificationManager notificationManager = getSystemService(NotificationManager.class);notificationManager.createNotificationChannel(channel);}//设置服务跳转Intent intent = new Intent(this, MainActivity.class);intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "CHANNEL_ID")// 设置通知的小图标。.setSmallIcon(R.mipmap.ic_launcher)//设置通知的标题。.setContentTitle(getString(R.string.app_name))//设置通知的内容.setContentText("进程守护中")//设置通知的优先级。.setPriority(NotificationCompat.PRIORITY_DEFAULT)//震动模式的通知在Android O及以上。.setVibrate(new long[]{0, 1000, 500, 1000})//在Android O及以上的系统上使用LED光色和微信号。.setLights(Color.RED, 1000, 1000)//设置Android O及以上版本的通知声音。.setSound(Uri.parse("android.resource://" + this.getPackageName() + "/raw/notification_sound"))//如果需要,在Android O及以上版本设置较大的通知标题。// .setLargeTitle("Large Title Text")//如果需要,在Android O及以上版本设置通知的子文本。// .setSubText("Sub Text")//如果需要,在Android O及以上版本设置大字体通知。// .setStyle(new NotificationCompat.BigTextStyle().bigText("Big Text"))//如果需要,在Android O及以上版本设置通知摘要文本(当有多个具有相同优先级的通知时显示摘要文本)。// .setSummaryText("Summary Text")//如果需要,在通知中添加动作按钮(可用于启动活动或发送广播)。// .addAction(R.drawable.ic_action, "Action Title", PendingIntent)//设置可点击跳转.setContentIntent(pendingIntent);// 将通知设置为前台服务startForeground(1, builder.build());}@Overridepublic int onStartCommand(Intent intent, int flags, int startId) {// 在这里执行需要在前台运行的任务// 返回START_STICKY表示服务在被杀死后会自动重启return START_STICKY;}@Nullable@Overridepublic IBinder onBind(Intent intent) {return null;}@Overridepublic void onDestroy() {super.onDestroy();// 停止前台服务stopForeground(true);stopSelf();}
}

application中添加服务

<serviceandroid:name=".service.ForegroundService"android:enabled="true"android:exported="false" />

activity中启动服务

Intent intent = new Intent(this, ForegroundService.class);
// Android 8.0使用startForegroundService在前台启动新服务
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {startForegroundService(intent);
} else {startService(intent);

创建通知

 模拟发送通知

binding.iv.setOnClickListener(v ->showNotification(getString(R.string.app_name), dateToString(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss") + "您收到一条消息")
);

创建通知及通知点击取消通知

private NotificationCompat.Builder builder;
private NotificationManagerCompat manager;private void showNotification(String title, String content) {// 创建通知频道,如果用户没有创建,则会自动创建。String CHANNEL_ID = "message";if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {if (getSystemService(NotificationManager.class).getNotificationChannel(CHANNEL_ID) == null) {NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "消息", NotificationManager.IMPORTANCE_DEFAULT);//通知的振动模式。channel.setVibrationPattern(new long[]{0, 1000, 500, 1000});//为通知通道启用振动。channel.enableVibration(true);//设置通道的颜色。channel.setLightColor(Color.RED);//设置通道的锁屏可见性。channel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC);getSystemService(NotificationManager.class).createNotificationChannel(channel);}}//设置服务跳转Intent intent = new Intent(this, MainActivity.class);intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);PendingIntent pendingIntent = PendingIntent.getActivity(this, 2, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);// 创建并分发通知。builder = new NotificationCompat.Builder(this, CHANNEL_ID)// 设置通知的小图标。.setSmallIcon(R.mipmap.ic_launcher)//设置通知的标题。.setContentTitle(title)//设置通知的内容.setContentText(content)//设置通知的优先级。.setPriority(NotificationCompat.PRIORITY_DEFAULT)//震动模式的通知在Android O及以上。.setVibrate(new long[]{0, 1000, 500, 1000})//在Android O及以上的系统上使用LED光色和微信号。.setLights(Color.RED, 1000, 1000)//设置Android O及以上版本的通知声音。.setSound(Uri.parse("android.resource://" + this.getPackageName() + "/raw/notification_sound"))//如果需要,在Android O及以上版本设置较大的通知标题。// .setLargeTitle("Large Title Text")//如果需要,在Android O及以上版本设置通知的子文本。// .setSubText("Sub Text")//如果需要,在Android O及以上版本设置大字体通知。// .setStyle(new NotificationCompat.BigTextStyle().bigText("Big Text"))//如果需要,在Android O及以上版本设置通知摘要文本(当有多个具有相同优先级的通知时显示摘要文本)。// .setSummaryText("Summary Text")//如果需要,在通知中添加动作按钮(可用于启动活动或发送广播)。// .addAction(R.drawable.ic_action, "Action Title", PendingIntent)//设置可点击跳转.setContentIntent(pendingIntent)//开启点按通知后自动移除通知.setAutoCancel(true);manager = NotificationManagerCompat.from(this);if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {checkPostNotificationPermission();} else {// 在 Android 10 或更早版本中,不需要请求此权限。//ID要和前台服务ID区分开,相同ID只能显示一条通知。manager.notify(2, builder.build());}

activity完整代码

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;import android.Manifest;
import android.app.Activity;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.widget.Toast;import com.example.javatest.databinding.ActivityMainBinding;
import com.example.javatest.service.ForegroundService;import java.text.SimpleDateFormat;
import java.util.Date;public class MainActivity extends AppCompatActivity {private ActivityMainBinding binding;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);binding = ActivityMainBinding.inflate(getLayoutInflater());setContentView(binding.getRoot());initView();initData();}private void initView() {//android 13及以上系统动态获取通知权限if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {checkPostNotificationPermission();}Intent intent = new Intent(this, ForegroundService.class);// Android 8.0使用startForegroundService在前台启动新服务if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {startForegroundService(intent);} else {startService(intent);}}private void initData() {binding.iv.setOnClickListener(v ->showNotification(getString(R.string.app_name), dateToString(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss") + "您收到一条消息"));}private String dateToString(long time, String format) {Date date = new Date(time);SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);return simpleDateFormat.format(date);}private NotificationCompat.Builder builder;private NotificationManagerCompat manager;private void showNotification(String title, String content) {// 创建通知频道,如果用户没有创建,则会自动创建。String CHANNEL_ID = "message";if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {if (getSystemService(NotificationManager.class).getNotificationChannel(CHANNEL_ID) == null) {NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "消息", NotificationManager.IMPORTANCE_DEFAULT);//通知的振动模式。channel.setVibrationPattern(new long[]{0, 1000, 500, 1000});//为通知通道启用振动。channel.enableVibration(true);//设置通道的颜色。channel.setLightColor(Color.RED);//设置通道的锁屏可见性。channel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC);getSystemService(NotificationManager.class).createNotificationChannel(channel);}}//设置服务跳转Intent intent = new Intent(this, MainActivity.class);intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);PendingIntent pendingIntent = PendingIntent.getActivity(this, 2, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);// 创建并分发通知。builder = new NotificationCompat.Builder(this, CHANNEL_ID)// 设置通知的小图标。.setSmallIcon(R.mipmap.ic_launcher)//设置通知的标题。.setContentTitle(title)//设置通知的内容.setContentText(content)//设置通知的优先级。.setPriority(NotificationCompat.PRIORITY_DEFAULT)//震动模式的通知在Android O及以上。.setVibrate(new long[]{0, 1000, 500, 1000})//在Android O及以上的系统上使用LED光色和微信号。.setLights(Color.RED, 1000, 1000)//设置Android O及以上版本的通知声音。.setSound(Uri.parse("android.resource://" + this.getPackageName() + "/raw/notification_sound"))//如果需要,在Android O及以上版本设置较大的通知标题。// .setLargeTitle("Large Title Text")//如果需要,在Android O及以上版本设置通知的子文本。// .setSubText("Sub Text")//如果需要,在Android O及以上版本设置大字体通知。// .setStyle(new NotificationCompat.BigTextStyle().bigText("Big Text"))//如果需要,在Android O及以上版本设置通知摘要文本(当有多个具有相同优先级的通知时显示摘要文本)。// .setSummaryText("Summary Text")//如果需要,在通知中添加动作按钮(可用于启动活动或发送广播)。// .addAction(R.drawable.ic_action, "Action Title", PendingIntent)//设置可点击跳转.setContentIntent(pendingIntent)//开启点按通知后自动移除通知.setAutoCancel(true);manager = NotificationManagerCompat.from(this);if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {checkPostNotificationPermission();} else {// 在 Android 10 或更早版本中,不需要请求此权限。//显示ID为1的通知(您可以使用任何您想要的ID)。manager.notify(2, builder.build());}}private void checkPostNotificationPermission() {if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS)!= PackageManager.PERMISSION_GRANTED) {ActivityCompat.requestPermissions((Activity) this, new String[]{Manifest.permission.POST_NOTIFICATIONS}, 200);} else if (manager != null) {//显示ID为1的通知(您可以使用任何您想要的ID)。manager.notify(2, builder.build());}}@Overridepublic void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {super.onRequestPermissionsResult(requestCode, permissions, grantResults);if (requestCode == 200) {if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {//允许了通知权限} else {Toast.makeText(this, "您拒绝了通知权限", Toast.LENGTH_SHORT).show();}}}
}

完整配置文件AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"><!--网络权限--><uses-permission android:name="android.permission.INTERNET" /><!--前台服务权限--><uses-permission android:name="android.permission.FOREGROUND_SERVICE" /><!--振动器权限--><uses-permission android:name="android.permission.VIBRATE" /><!--全屏意图权限--><uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" /><!--发布通知权限--><uses-permission android:name="android.permission.POST_NOTIFICATIONS" /><applicationandroid:allowBackup="true"android:dataExtractionRules="@xml/data_extraction_rules"android:fullBackupContent="@xml/backup_rules"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"android:theme="@style/Theme.JavaTest"tools:targetApi="31"><activityandroid:name=".MainActivity"android:exported="true"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><serviceandroid:name=".service.ForegroundService"android:enabled="true"android:exported="false" /></application></manifest>

build.gradle.kts文件中添加viewBinding支持

buildFeatures{viewBinding = true
}

相关文章:

Android前台服务和通知

前台服务 Android 13及以上系统需要动态获取通知权限。 //android 13及以上系统动态获取通知权限 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {checkPostNotificationPermission(); } private void checkPostNotificationPermission() {if (ActivityCompat.chec…...

算法进修Day-36

算法进修Day-36 71. 简化路径 难度&#xff1a;中等 题目要求&#xff1a; 给你一个字符串 path &#xff0c;表示指向某一文件或目录的 Unix 风格 绝对路径 &#xff08;以 / 开头&#xff09;&#xff0c;请你将其转化为更加简洁的规范路径。 在 Unix 风格的文件系统中&am…...

postman自动化运行接口测试用例

做过接口测试的人&#xff0c;应该都知道postman &#xff0c;我们在日常的时候都可以利用postman做接口测试&#xff0c;我们可以把接口的case保存下来在collection里面&#xff0c;那么可能会有这样的需求&#xff0c;我们怎么把collection的用例放到jenkins中定时执行呢&…...

【Linux】Linux环境搭建

Linux环境搭建 前言Linux 环境的搭建方式一、Linux环境搭载购买云服务器 二、 使用 XShell 远程登陆到 Linux关于 Linux 桌面下载安装 XShell查看 Linux 主机 ip使用 XShell 登陆主机XShell 下的复制粘贴 前言 Linux 环境的搭建方式 主要有三种 直接安装在 物理机 上. 但是由…...

k8s day07

昨日内容回顾: - 污点: 影响Pod调度&#xff0c;污点是作用在worker节点上。语法格式: KEY[VALUE]:EFFECT 有三种污点。 EFFECT: - NoSchedule&#xff1a; 已经调度到当前节点的Pod不驱逐&#xff0c;并且不在接…...

压力大,休息日都没有,更别说年休假了

我一周要工作六天&#xff0c;每天至少十小时&#xff0c;连个休息日都没有。哪来的年休假&#xff1f;...

人手一个助理,三句话让AI替我们上班

目录 前言 从大模型上长出来的 AI 原生应用&#xff0c;才是关键 而这看起来只是一个小小的办公沟通场景&#xff0c;却是大模型重构的一个非常典型的场景。背后考验的也是大模型的综合能力应用 这种从AI原生角度进行的重构&#xff0c;离不开大模型的理解、生成、逻辑、记…...

【Eclipse Maven Tycho】如何通过maven执行eclipse application

通过maven执行eclipse application 前言命令行下运行通过maven tycho运行 前言 eclipse其实不只是一个桌面&#xff08;GUI&#xff09;程序&#xff0c;他还可以是一个命令行程序。如果你的产品或软件是基于eclipse开发的&#xff0c;并且他没有UI相关的功能&#xff0c;那么…...

(一)docker:建立oracle数据库

前言&#xff0c;整个安装过程主要根据docker-images/OracleDatabase/SingleInstance /README.md &#xff0c;里边对如何制作容器讲的比较清楚&#xff0c;唯一问题就是都是英文&#xff0c;可以使用谷歌浏览器自动翻译成中文&#xff0c;自己再对照英文相互参照来制作提前准备…...

在配置文件“tsconfig.json”中找不到任何输入。指定的 “include“ 路径为“[“**/*“]”,“exclude“ 路径为[]

在vscode中项目下的tsconfig.json莫名报错 解决办法 在目录中随便创建一个后缀为.ts的文件 便不再报错...

java编译时指定classpath

说明 Java编译时可以通过选项--class-path <path>&#xff0c;或者 -classpath <path>&#xff0c;或者-cp <path>来指定查找用户类文件、注释程序处理程序、或者源文件的位置。这个设置覆盖CLASSPATH环境变量的设置。如果没有设置-sourcepath&#xff0c;那…...

分享一下抽奖活动小程序怎么做

在当今数字化时代&#xff0c;抽奖活动小程序已成为一种高效、创新的营销方式。它不仅能够吸引用户的注意力&#xff0c;提高品牌知名度&#xff0c;还能促进用户参与度&#xff0c;增强用户对品牌的忠诚度。本文将详细介绍如何制作一个成功的抽奖活动小程序&#xff0c;以及它…...

同为科技(TOWE)工业级多位USB快充桌面PDU插座

如今&#xff0c;许多便捷式、轻薄化电子设备越来越多&#xff0c;很多设备上预留的端口越来越少&#xff0c;甚至很多款笔记本电脑只预留了一个单一的Type-C接口。这样做虽然在体验感、美观度和轻薄尺寸的优势显而易见&#xff0c;然而也存在接口不足的明显弊端。USB快充插排产…...

testt

wd wwwwwwwwwwwwww qdwqdwqd...

Git Bash(一)Windows下安装及使用

目录 一、简介1.1 什么是Git&#xff1f;1.2 Git 的主要特点1.3 什么是 Git Bash&#xff1f; 二、下载三、安装3.1 同意协议3.2 选择安装位置3.3 其他配置&#xff08;【Next】 即可&#xff09;3.4 安装完毕3.5 打开 Git Bash 官网地址&#xff1a; https://www.git-scm.com/…...

软考公告 | 关于2023年下半年软考批次安排

按照《2023年下半年计算机技术与软件专业技术资格&#xff08;水平&#xff09;考试有关工作调整的通告》&#xff0c;自2023年下半年起&#xff0c;计算机软件资格考试方式均由纸笔考试改革为计算机化考试。 为进一步提升考试服务质量和水平, 便利考生考试, 减少考生参加考试…...

react 中ref 属性的三种写法

目录 1. 字符串 ref 2.dom节点上使用回调函数ref 3.React.createRef() 1. 字符串 ref 最早的ref用法。&#xff08;由于效率问题&#xff0c;现在官方不推荐使用这种写法。&#xff09; 1.dom节点上使用&#xff0c;通过this.refs.xxxx来引用真实的dom节点 <input ref&q…...

v4l2-ioctl.c的一些学习和整理

可以发现&#xff0c;这个宏用的很好&#xff0c;简洁易扩展&#xff0c;自己写代码可以学习下 #define IOCTL_INFO(_ioctl, _func, _debug, _flags) \[_IOC_NR(_ioctl)] { \.ioctl _ioctl, \.flags _flags, \.name #_ioctl, \.func _func, \.debug _…...

Python实战小项目分享

Python实战小项目包括网络爬虫、数据分析和可视化、文本处理、图像处理、聊天机器人、任务管理工具、游戏开发和网络服务器等。这些项目提供了实际应用场景和问题解决思路&#xff0c;可以选择感兴趣的项目进行实践&#xff0c;加深对Python编程的理解和掌握。在实践过程中&…...

使用Dockerfile生成docker镜像和容器的方法记录

一、相关介绍 Docker 是一个开源的容器化平台&#xff0c;其中的主要概念是容器和镜像。 容器是 Docker 的运行实例。 它是一个独立并可执行的软件包&#xff0c;包含了应用程序及其依赖的所有组件&#xff08;如代码、运行时环境、系统工具、库文件等&#xff09;。容器可以在…...

React hook之useRef

React useRef 详解 useRef 是 React 提供的一个 Hook&#xff0c;用于在函数组件中创建可变的引用对象。它在 React 开发中有多种重要用途&#xff0c;下面我将全面详细地介绍它的特性和用法。 基本概念 1. 创建 ref const refContainer useRef(initialValue);initialValu…...

【位运算】消失的两个数字(hard)

消失的两个数字&#xff08;hard&#xff09; 题⽬描述&#xff1a;解法&#xff08;位运算&#xff09;&#xff1a;Java 算法代码&#xff1a;更简便代码 题⽬链接&#xff1a;⾯试题 17.19. 消失的两个数字 题⽬描述&#xff1a; 给定⼀个数组&#xff0c;包含从 1 到 N 所有…...

java调用dll出现unsatisfiedLinkError以及JNA和JNI的区别

UnsatisfiedLinkError 在对接硬件设备中&#xff0c;我们会遇到使用 java 调用 dll文件 的情况&#xff0c;此时大概率出现UnsatisfiedLinkError链接错误&#xff0c;原因可能有如下几种 类名错误包名错误方法名参数错误使用 JNI 协议调用&#xff0c;结果 dll 未实现 JNI 协…...

测试markdown--肇兴

day1&#xff1a; 1、去程&#xff1a;7:04 --11:32高铁 高铁右转上售票大厅2楼&#xff0c;穿过候车厅下一楼&#xff0c;上大巴车 &#xffe5;10/人 **2、到达&#xff1a;**12点多到达寨子&#xff0c;买门票&#xff0c;美团/抖音&#xff1a;&#xffe5;78人 3、中饭&a…...

高危文件识别的常用算法:原理、应用与企业场景

高危文件识别的常用算法&#xff1a;原理、应用与企业场景 高危文件识别旨在检测可能导致安全威胁的文件&#xff0c;如包含恶意代码、敏感数据或欺诈内容的文档&#xff0c;在企业协同办公环境中&#xff08;如Teams、Google Workspace&#xff09;尤为重要。结合大模型技术&…...

使用 Streamlit 构建支持主流大模型与 Ollama 的轻量级统一平台

🎯 使用 Streamlit 构建支持主流大模型与 Ollama 的轻量级统一平台 📌 项目背景 随着大语言模型(LLM)的广泛应用,开发者常面临多个挑战: 各大模型(OpenAI、Claude、Gemini、Ollama)接口风格不统一;缺乏一个统一平台进行模型调用与测试;本地模型 Ollama 的集成与前…...

SiFli 52把Imagie图片,Font字体资源放在指定位置,编译成指定img.bin和font.bin的问题

分区配置 (ptab.json) img 属性介绍&#xff1a; img 属性指定分区存放的 image 名称&#xff0c;指定的 image 名称必须是当前工程生成的 binary 。 如果 binary 有多个文件&#xff0c;则以 proj_name:binary_name 格式指定文件名&#xff0c; proj_name 为工程 名&…...

Go 语言并发编程基础:无缓冲与有缓冲通道

在上一章节中&#xff0c;我们了解了 Channel 的基本用法。本章将重点分析 Go 中通道的两种类型 —— 无缓冲通道与有缓冲通道&#xff0c;它们在并发编程中各具特点和应用场景。 一、通道的基本分类 类型定义形式特点无缓冲通道make(chan T)发送和接收都必须准备好&#xff0…...

LangChain知识库管理后端接口:数据库操作详解—— 构建本地知识库系统的基础《二》

这段 Python 代码是一个完整的 知识库数据库操作模块&#xff0c;用于对本地知识库系统中的知识库进行增删改查&#xff08;CRUD&#xff09;操作。它基于 SQLAlchemy ORM 框架 和一个自定义的装饰器 with_session 实现数据库会话管理。 &#x1f4d8; 一、整体功能概述 该模块…...

Linux系统部署KES

1、安装准备 1.版本说明V008R006C009B0014 V008&#xff1a;是version产品的大版本。 R006&#xff1a;是release产品特性版本。 C009&#xff1a;是通用版 B0014&#xff1a;是build开发过程中的构建版本2.硬件要求 #安全版和企业版 内存&#xff1a;1GB 以上 硬盘&#xf…...