android远程更新下载apk

最近业务有涉及到,奈何是个app代码小白,遂记录一下

一:AndroidManifest.xml文件配置

application标签里面加上

android:networkSecurityConfig="@xml/network_config"

<!--    app下载更新配置-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- 在SDCard中创建与删除文件权限 -->
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" tools:ignore="ProtectedPermissions" />
<!-- 存储权限 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- 安装APK权限 -->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /><!-- 将以下 <provider> 标签移动到 <application> 标签内部 -->
<providerandroid:name="androidx.core.content.FileProvider"android:authorities="com.shuye.znsy.fileprovider"android:exported="false"android:grantUriPermissions="true"><meta-dataandroid:name="android.support.FILE_PROVIDER_PATHS"android:resource="@xml/file_paths" />
</provider>

 

二:file_paths.xml

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android"><!--安装包文件存储路径--><external-files-pathname="my_download"path="Download" /><external-pathname="."path="." />
</paths>

三:network_config.xml文件

<?xml version="1.0" encoding="utf-8"?>
<network-security-config><base-config cleartextTrafficPermitted="true" />
</network-security-config>

如果没有这两个文件需要新建然后将以上美容复制进去

四:progress.xml滚动条布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><LinearLayoutandroid:id="@+id/titleBar"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:id="@+id/txtStatus"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="状态"android:textSize="10sp"android:textStyle="normal" /><ProgressBarandroid:id="@+id/progress"style="?android:attr/progressBarStyleHorizontal"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_toLeftOf="@id/txtStatus" /></LinearLayout>
</LinearLayout>

五:新建AutoUpdater.java  这里是核心

package com.shuye.znsy.update;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;import androidx.core.content.FileProvider;import com.shuye.znsy.BuildConfig;
import com.shuye.znsy.R;import org.json.JSONException;
import org.json.JSONObject;import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;public class AutoUpdater {// 下载安装包的网络路径private String apkUrl = BuildConfig.host + "app/upload/download-apk";protected String checkUrl = apkUrl + "/output-metadata-json";// 保存APK的文件名private static final String saveFileName = "my.apk";private static File apkFile;// 下载线程private Thread downLoadThread;private int progress;// 当前进度// 应用程序Contextprivate Context mContext;// 是否是最新的应用,默认为falseprivate boolean isNew = false;private boolean intercept = false;// 进度条与通知UI刷新的handler和msg常量private ProgressBar mProgress;private TextView txtStatus;private static final int DOWN_UPDATE = 1;private static final int DOWN_OVER = 2;private static final int SHOWDOWN = 3;public AutoUpdater(Context context) {mContext = context;apkFile = new File(mContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), saveFileName);}public void ShowUpdateDialog() {AlertDialog.Builder builder = new AlertDialog.Builder(mContext);builder.setTitle("软件版本更新");builder.setMessage("有最新的软件包,请下载并安装!");builder.setPositiveButton("立即下载", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {ShowDownloadDialog();}});//按钮隐藏,只能下载更新
//        builder.setNegativeButton("以后再说", new DialogInterface.OnClickListener() {
//            @Override
//            public void onClick(DialogInterface dialog, int which) {
//                dialog.dismiss();
//            }
//        });AlertDialog dialog = builder.create();dialog.setOnShowListener(new DialogInterface.OnShowListener() {@Overridepublic void onShow(DialogInterface dialogInterface) {Button btnPos = dialog.getButton(DialogInterface.BUTTON_POSITIVE);Button btnNeg = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);if (btnPos != null) {btnPos.setTextColor(Color.WHITE);}if (btnNeg != null) {btnNeg.setTextColor(Color.WHITE);}}});// 设置点击空白区域不关闭对话框dialog.setCanceledOnTouchOutside(false);//这里设置点击返回按钮对话框不消失dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {@Overridepublic boolean onKey(DialogInterface dialogInterface, int keyCode, KeyEvent keyEvent) {if (keyCode == KeyEvent.KEYCODE_BACK) {// 拦截返回按钮事件,不做任何操作return true;}return false;}});dialog.show();}private void ShowDownloadDialog() {AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mContext);dialogBuilder.setTitle("软件版本更新");LayoutInflater inflater = LayoutInflater.from(mContext);View v = inflater.inflate(R.layout.progress, null);mProgress = (ProgressBar) v.findViewById(R.id.progress);txtStatus = v.findViewById(R.id.txtStatus);dialogBuilder.setView(v);dialogBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {intercept = true;}});AlertDialog dialog = dialogBuilder.create();dialog.setOnShowListener(new DialogInterface.OnShowListener() {@Overridepublic void onShow(DialogInterface dialogInterface) {Button btnNeg = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);if (btnNeg != null) {btnNeg.setTextColor(Color.WHITE);}}});// 设置点击空白区域不关闭对话框dialog.setCanceledOnTouchOutside(false);//这里设置点击返回按钮对话框不消失dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {@Overridepublic boolean onKey(DialogInterface dialogInterface, int keyCode, KeyEvent keyEvent) {if (keyCode == KeyEvent.KEYCODE_BACK) {// 拦截返回按钮事件,不做任何操作return true;}return false;}});dialog.show();DownloadApk();}/*** 检查是否更新的内容*/public void CheckUpdate() {new Thread(new Runnable() {@Overridepublic void run() {try {String localVersion = "1";try {localVersion = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionName;} catch (PackageManager.NameNotFoundException e) {e.printStackTrace();}String versionName = "1";String outputFile = "";String config = doGet(checkUrl);if (config != null && config.length() > 0) {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {Matcher m = Pattern.compile("\"outputFile\":\\s*\"(?<m>[^\"]*?)\"").matcher(config);if (m.find()) {outputFile = m.group("m");}m = Pattern.compile("\"versionName\":\\s*\"(?<m>[^\"]*?)\"").matcher(config);if (m.find()) {String v = m.group("m");versionName = m.group("m").replace("v1.0.", "");}}}if (localVersion.contains(".")) {localVersion = localVersion.substring(0, localVersion.indexOf("."));}if (versionName.contains(".")) {versionName = versionName.substring(0, versionName.indexOf("."));}//测试环境 大于号 正式上线要改成小于号,<<<<<<<<<<<<<<<<<<<<<<if (Long.parseLong(localVersion) > Long.parseLong(versionName)) {
//                    apkUrl = apkUrl + outputFile;mHandler.post(new Runnable() {@Overridepublic void run() {System.out.println("版本升级开始自动更新--------------------" + apkUrl);mHandler.sendEmptyMessage(SHOWDOWN);}});} else {// 当前版本已是最新版本return;}} catch (Exception e) {e.printStackTrace();}}}).start();}/*** 从服务器下载APK安装包*/public void DownloadApk() {downLoadThread = new Thread(DownApkWork);downLoadThread.start();}private Runnable DownApkWork = new Runnable() {@Overridepublic void run() {URL url;try {url = new URL(apkUrl);HttpURLConnection conn = (HttpURLConnection) url.openConnection();conn.connect();int length = conn.getContentLength();InputStream ins = conn.getInputStream();FileOutputStream fos = new FileOutputStream(apkFile);int count = 0;byte[] buf = new byte[1024];while (!intercept) {int numread = ins.read(buf);count += numread;progress = (int) (((float) count / length) * 100);// 下载进度mHandler.sendEmptyMessage(DOWN_UPDATE);if (numread <= 0) {// 下载完成通知安装mHandler.sendEmptyMessage(DOWN_OVER);break;}fos.write(buf, 0, numread);}fos.close();ins.close();} catch (Exception e) {e.printStackTrace();}}};/*** 安装APK内容*/public void installAPK() {try {if (!apkFile.exists()) {return;}Intent intent = new Intent(Intent.ACTION_VIEW);intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//安装完成后打开新版本intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // 给目标应用一个临时授权if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {//判断版本大于等于7.0//如果SDK版本>=24,即:Build.VERSION.SDK_INT >= 24,使用FileProvider兼容安装apkString packageName = mContext.getApplicationContext().getPackageName();String authority = new StringBuilder(packageName).append(".fileprovider").toString();Uri apkUri = FileProvider.getUriForFile(mContext, authority, apkFile);intent.setDataAndType(apkUri, "application/vnd.android.package-archive");} else {intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");}// 添加权限请求intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);mContext.startActivity(intent);android.os.Process.killProcess(android.os.Process.myPid());//安装完之后会提示”完成” “打开”。} catch (Exception e) {e.printStackTrace();// 添加异常处理,打印异常信息或者显示Toast提示Toast.makeText(mContext, "安装APK出错", Toast.LENGTH_SHORT).show();}}private Handler mHandler = new Handler() {public void handleMessage(android.os.Message msg) {switch (msg.what) {case SHOWDOWN:ShowUpdateDialog();break;case DOWN_UPDATE:txtStatus.setText(progress + "%");mProgress.setProgress(progress);break;case DOWN_OVER:Toast.makeText(mContext, "下载完毕", Toast.LENGTH_SHORT).show();installAPK();break;default:break;}}};public static String doGet(String httpurl) {HttpURLConnection connection = null;InputStream is = null;BufferedReader br = null;String result = null;try {URL url = new URL(httpurl);connection = (HttpURLConnection) url.openConnection();connection.setRequestMethod("GET");connection.setConnectTimeout(15000);connection.setReadTimeout(60000);connection.connect();if (connection.getResponseCode() == 200) {is = connection.getInputStream();br = new BufferedReader(new InputStreamReader(is, "UTF-8"));StringBuffer sbf = new StringBuffer();String temp = null;while ((temp = br.readLine()) != null) {sbf.append(temp);sbf.append("\r\n");}result = sbf.toString();}} catch (MalformedURLException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} finally {if (null != br) {try {br.close();} catch (IOException e) {e.printStackTrace();}}if (null != is) {try {is.close();} catch (IOException e) {e.printStackTrace();}}connection.disconnect();}return result;}
}
六:MainActivity.java

 /*** app检查更新*/private void appUpdata(){//检查更新try {//6.0才用动态权限if (Build.VERSION.SDK_INT >= 23) {String[] permissions = {Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.ACCESS_WIFI_STATE,Manifest.permission.INTERNET};List<String> permissionList = new ArrayList<>();for (int i = 0; i < permissions.length; i++) {if (ActivityCompat.checkSelfPermission(this, permissions[i]) != PackageManager.PERMISSION_GRANTED) {permissionList.add(permissions[i]);}}if (permissionList.size() <= 0) {//说明权限都已经通过,可以做你想做的事情去//自动更新AutoUpdater manager = new AutoUpdater(MainActivity.this);manager.CheckUpdate();} else {//存在未允许的权限ActivityCompat.requestPermissions(this, permissions, 100);}}} catch (Exception ex) {Toast.makeText(MainActivity.this, "自动更新异常:" + ex.getMessage(), Toast.LENGTH_SHORT).show();}}@Overridepublic void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {super.onRequestPermissionsResult(requestCode, permissions, grantResults);boolean haspermission = false;if (100 == requestCode) {for (int i = 0; i < grantResults.length; i++) {if (grantResults[i] == -1) {haspermission = true;}}if (haspermission) {//跳转到系统设置权限页面,或者直接关闭页面,不让他继续访问permissionDialog();} else {//全部权限通过,可以进行下一步操作AutoUpdater manager = new AutoUpdater(MainActivity.this);manager.CheckUpdate();}}}AlertDialog alertDialog;//打开手动设置应用权限private void permissionDialog() {if (alertDialog == null) {alertDialog = new AlertDialog.Builder(this).setTitle("提示信息").setMessage("当前应用缺少必要权限,该功能暂时无法使用。如若需要,请单击【确定】按钮前往设置中心进行权限授权。").setPositiveButton("设置", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {cancelPermissionDialog();Uri packageURI = Uri.parse("package:" + getPackageName());Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageURI);startActivity(intent);}}).setNegativeButton("取消", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {cancelPermissionDialog();}}).create();}alertDialog.show();}private void cancelPermissionDialog() {alertDialog.cancel();}private static final long HEARTBEAT_INTERVAL = 60 * 60 * 1000; // 1小时的毫秒数
//    private static final long HEARTBEAT_INTERVAL = 1 * 60 * 1000; // 每隔一分钟的毫秒数private Handler heartbeatHandler = new Handler();private Runnable heartbeatRunnable = new Runnable() {@Overridepublic void run() {appUpdata(); // 调用appUpdata()方法heartbeatHandler.postDelayed(this, HEARTBEAT_INTERVAL); // 每隔1小时再次执行}};private void startHeartbeat() {heartbeatHandler.postDelayed(heartbeatRunnable, HEARTBEAT_INTERVAL);}private void stopHeartbeat() {heartbeatHandler.removeCallbacks(heartbeatRunnable);}}

然后在creat里面调用心跳

 @Overrideprotected void onCreate(Bundle savedInstanceState) {//其他代码省略 startHeartbeat();}

这里要说一下,打包的时候可以根据当前时间设置,修改build.gradle文件

plugins {id 'com.android.application'//添加如下配置id 'com.huawei.agconnect'
}
apply plugin: 'com.huawei.agconnect'android {compileSdk 31defaultConfig {applicationId "com.shuye.znsy"minSdk 21targetSdk 31versionCode 1
//        versionName "1.0"versionName "${releaseTime()}"testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"}buildTypes {debug {signingConfig signingConfigs.debugdebuggable trueminifyEnabled falsebuildConfigField("String", "host", "\"http://192.168.100.111:8001/\"")proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'android.applicationVariants.all { variant ->variant.outputs.all {outputFileName = "my_${releaseTime()}.apk"}}}release {minifyEnabled falseshrinkResources falsezipAlignEnabled truejniDebuggable falsedebuggable falsebuildConfigField("String", "host", "\"http://192.168.100.111:8001/\"")proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'android.applicationVariants.all { variant ->variant.outputs.all {outputFileName = "my_${releaseTime()}.apk"}}}}compileOptions {sourceCompatibility JavaVersion.VERSION_1_8targetCompatibility JavaVersion.VERSION_1_8}
}dependencies {implementation 'androidx.appcompat:appcompat:1.3.0'implementation 'com.google.android.material:material:1.4.0'implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
//    implementation 'androidx.media3:media3-common:+'testImplementation 'junit:junit:4.13.2'androidTestImplementation 'androidx.test.ext:junit:1.1.3'androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'implementation 'com.github.Jasonchenlijian:FastBle:2.4.0'implementation 'com.huawei.hms:scanplus:2.12.0.301'//数据解析相关implementation 'com.alibaba:fastjson:1.2.37'implementation 'io.reactivex:rxjava:1.3.0'implementation 'io.reactivex:rxandroid:1.2.1'implementation 'com.google.code.gson:gson:2.8.6'implementation 'com.orhanobut:logger:2.1.1'//网络框架implementation 'com.squareup.retrofit2:retrofit:2.4.0'implementation 'com.squareup.retrofit2:converter-gson:2.4.0'implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'implementation 'io.reactivex.rxjava2:rxjava:2.1.16'implementation 'com.squareup.okhttp3:okhttp:3.11.0'implementation 'com.squareup.okhttp3:logging-interceptor:3.8.1'//eventbusimplementation 'org.greenrobot:eventbus:3.0.0'}
def releaseTime() {return new Date().format("yyyyMMddHHmmss", TimeZone.getTimeZone("UTC"))
}

打包后得到的文件

以上是app内所要修改或添加全部代码,注意这里需要配合后端下载文件联合使用,考虑到这里遂上一下后端代码,每个人情况不一样,仅供参考

我这里是springboot框架,java语言

一个为下载文件apk的方法,另外一个读取output-metadata.json反馈到app进行版本解析比较

注意这里我后端已经有了文件上传的方法,我是将apk和output-metadata.json一起上传到了服务器上面

package com.cz.hospital.base.controller.pad;import com.cz.hospital.base.service.IPackageUploadService;
import com.cz.hospital.base.service.IUserService;
import com.cz.hospital.entity.attachment.AttachmentEntity;
import com.cz.hospital.entity.packageupload.vo.PackageUploadVo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.UrlResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;@Slf4j
@RestController
@RequestMapping("/app/upload")
@Api(tags = "app安装包下载管理接口")
public class AppUpdateController {@Resourceprivate IPackageUploadService packageUploadService;@Resourceprivate IUserService userService;@RequestMapping("/download-apk")public ResponseEntity<org.springframework.core.io.Resource> downloadNewestFile() throws IOException {PackageUploadVo vo = packageUploadService.findNewestList();List<AttachmentEntity> attachmentList = vo.getAttachmentList();AttachmentEntity file = new AttachmentEntity();if( attachmentList.size()>0 ){if( attachmentList.size()>0 ){for( AttachmentEntity aeF : attachmentList ){if( ".apk".equals( aeF.getFileExtension() ) ){file = aeF;}}}}String filePath = file.getFileStoragePath();String fileName = file.getFileName();// 创建文件资源对象Path path = Paths.get(filePath);org.springframework.core.io.Resource resource = new UrlResource(path.toUri());// 设置响应头HttpHeaders headers = new HttpHeaders();headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + fileName);headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);headers.set(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename*=UTF-8''" + URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString()));headers.set(HttpHeaders.CONTENT_ENCODING, "UTF-8");headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename*=UTF-8''" + URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString()));// 返回文件内容return ResponseEntity.ok().headers(headers).contentLength(resource.contentLength()).contentType(MediaType.APPLICATION_OCTET_STREAM).body(resource);}@RequestMapping("/download-apk/output-metadata-json")public String readJson() throws IOException {PackageUploadVo vo = packageUploadService.findNewestList();List<AttachmentEntity> attachmentList = vo.getAttachmentList();AttachmentEntity file = new AttachmentEntity();if( attachmentList.size()>0 ){if( attachmentList.size()>0 ){for( AttachmentEntity aeF : attachmentList ){if( ".json".equals( aeF.getFileExtension() ) ){file = aeF;}}}}// 读取output-metadata.json文件String filePath = file.getFileStoragePath();String fileName = file.getFileName();// 创建文件资源对象Path path = Paths.get(filePath);org.springframework.core.io.Resource resource = new UrlResource(path.toUri());InputStream inputStream = resource.getInputStream();byte[] jsonBytes = FileCopyUtils.copyToByteArray(inputStream);String jsonContent = new String(jsonBytes, StandardCharsets.UTF_8);// 返回文件内容return jsonContent;}}

至此结束,有问题欢迎大家随时交流

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/275.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Qt 学习笔记】Qt常用控件 | 显示类控件Progress Bar的使用及说明

博客主页&#xff1a;Duck Bro 博客主页系列专栏&#xff1a;Qt 专栏关注博主&#xff0c;后期持续更新系列文章如果有错误感谢请大家批评指出&#xff0c;及时修改感谢大家点赞&#x1f44d;收藏⭐评论✍ Qt常用控件 | 显示类控件Progress Bar的使用及说明 文章编号&#xff…

网络防火墙技术知多少?了解如何保护您的网络安全

在当前以网络为核心的世界中&#xff0c;网络安全成为了至关重要的议题。网络防火墙是一种常见的保护网络安全的技术&#xff0c;用于监控和控制网络流量&#xff0c;阻止未经授权的访问和恶意活动。今天德迅云安全就带您了解下防火墙的一些相关功能和类型。 防火墙的五个功能…

(助力国赛)数学建模可视化!!!含代码1(折线图、地图(点)、地图(线)、地图(多边形)、地图(密度)、环形图、环形柱状图、局部放大图)

众所周知&#xff0c;数学建模的过程中&#xff0c;将复杂的数据和模型结果通过可视化图形呈现出来&#xff0c;不仅能够帮助我们更深入地理解问题&#xff0c;还能够有效地向评委展示我们的研究成果。   今天&#xff0c;作者将与大家分享8种强大的数学建模可视化图形及其在…

.Net RabbitMQ(消息队列)

文章目录 一.RabbitMQ 介绍以及工作模式1.RabbitMQ的介绍&#xff1a;2.RabbitMQ的工作模式&#xff1a; 二.RabbitMQ安装1.安装Erlang语言环境2.安装RabbitMQ 三.在.Net中使用RabbitMQ1.HelloWorld模式2.工作队列模式3.发布订阅模式4.Routing路由模式和Topics通配符模式 一.Ra…

使用Python工具库SnowNLP对评论数据标注(二)

这一次用pandas处理csv文件 comments.csv import pandas as pd from snownlp import SnowNLPdf pd.read_csv("C:\\Users\\zhour\\Documents\\comments.csv")#{a: [1, 2, 3], b: [4, 5, 6], c: [7, 8, 9]}是个字典 emotions[] for txt in df[sentence]:s SnowNLP(…

Kali Linux扩容(使用图形化界面)

因为今天在拉取vulhub中的镜像的时候报错空间不够&#xff0c;因为最开始只给了20GB的空间&#xff0c;所以现在需要扩容了&#xff0c;结合了一下网上的找到了简便的解决方法 1.首先虚拟机设置->磁盘->扩展 小插曲&#xff1a;在对虚拟机磁盘进行扩容以后&#xff0c;…

linux启动minicom、u-boot的常用命令、网络命令tftp、nfs/根文件系统、u-boot的bootargs环境变量

linux启动minicom sudo minicom -con进入minicom界面&#xff1a; 打开单片机 在打开之后&#xff0c;我们通过 printenv查看环境配置 在修改配置之前&#xff0c;我们最好先将环境初始化一下&#xff0c;初始化代码为 nand erase.chipu-boot的常用命令 尽管u-boot是一个…

ObjectMapper解析JSON数据

ObjectMapper的作用 1.背景&#xff1a; 当我们调用API的时候捕获的数据&#xff0c;往往需要结合文档所定义的类进行转换&#xff0c;也就是Java对象与JSON 字符串之间的转换 2.作用&#xff1a; ObjectMapper 是 Jackson 库中的一个关键类&#xff0c;它的作用是将 JSON 数据…

第七周学习笔记DAY.4-方法重写与多态

学完本次课程后&#xff0c;你能够&#xff1a; 实现方法重写 深入理解继承相关概念 了解Object类 会使用重写实现多态机制 会使用instanceof运算符 会使用向上转型 会使用向下转型 什么是方法重写 方法的重写或方法的覆盖&#xff08;overriding&#xff09; 1.子类根据…

【Python系列】非异步方法调用异步方法

&#x1f49d;&#x1f49d;&#x1f49d;欢迎来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 推荐:kwan 的首页,持续学…

C语言学习/复习23---

一、数据的存储 二、数据类型的介绍 三、整型在内存中的存储 将原码转换为补码。如果数是正数&#xff0c;则补码与原码相同&#xff1b;如果数是负数&#xff0c;则先将原码按位取反&#xff0c;然后加1。将补码转换原补码。如果数是正数&#xff0c;则补码与原码相同&#x…

【简单介绍下日常的启发式算法】

&#x1f3a5;博主&#xff1a;程序员不想YY啊 &#x1f4ab;CSDN优质创作者&#xff0c;CSDN实力新星&#xff0c;CSDN博客专家 &#x1f917;点赞&#x1f388;收藏⭐再看&#x1f4ab;养成习惯 ✨希望本文对您有所裨益&#xff0c;如有不足之处&#xff0c;欢迎在评论区提出…

CLSRSC-400: A system reboot is required to continue installing

RHEL 7.9ORACLE RAC 12.2.0.1.0&#xff0c;在运行root.sh脚本时&#xff0c;出现CLSRSC-400: A system reboot is required to continue installing报错 # /u01/app/12.2.0/grid/root.sh Performing root user operation.The following environment variables are set as:ORA…

在Windows安装R语言

直接安装R语言软件 下载网址&#xff1a;R: The R Project for Statistical Computing 下载点击install R for the first time 通过Anaconda下载RStudio 提前下载好Anaconda 点击Anaconda Navigate 点击RStudio的Install下载就好了

《大话数据结构》04 静态链表

1. 静态链表 其实C语言真是好东西&#xff0c;它具有的指针能力&#xff0c;使得它可以非常容易地操作内存中的地址和数据&#xff0c;这比其他高级语言更加灵活方便。后来的面向对象语言&#xff0c;如Java、C#等&#xff0c;虽不使用指针&#xff0c;但因为启用了对象引用机…

C语言进阶课程学习记录-第36课 - 函数与指针分析

C语言进阶课程学习记录-第36课 - 函数与指针分析 函数类型实验-函数指针实验-回调机制小结 本文学习自狄泰软件学院 唐佐林老师的 C语言进阶课程&#xff0c;图片全部来源于课程PPT&#xff0c;仅用于个人学习记录 函数类型 实验-函数指针 #include <stdio.h>typedef in…

PLC工业网关,实现PLC联网

在当今工业自动化领域&#xff0c;PLC&#xff08;可编程逻辑控制器&#xff09;作为控制系统的核心&#xff0c;其稳定性和可靠性至关重要。然而&#xff0c;随着工业互联网和智能制造的快速发展&#xff0c;如何实现PLC的联网通信&#xff0c;提高数据传输效率&#xff0c;成…

Redis教程——数据类型(哈希、集合)

上篇文章我们学习了Redis教程——数据类型&#xff08;字符串、列表&#xff09;&#xff0c;这篇文章学习Redis教程——数据类型&#xff08;哈希表、集合&#xff09; 哈希表Hash 哈希表是一个string类型的field(字段)和value(值)的映射表&#xff0c;hash特别适合用于存储…

C语言进阶课程学习记录-函数指针的阅读

C语言进阶课程学习记录-函数指针的阅读 5个标识符含义解析技巧 本文学习自狄泰软件学院 唐佐林老师的 C语言进阶课程&#xff0c;图片全部来源于课程PPT&#xff0c;仅用于个人学习记录 5个标识符含义解析 int (*p1) (int* , int (*f) ( int* ) );定义了指针p1,指向函数&#…

OpenHarmony实战开发-如何通过分割swiper区域,实现指示器导航点位于swiper下方的效果。

介绍 本示例介绍通过分割swiper区域&#xff0c;实现指示器导航点位于swiper下方的效果。 效果预览图 使用说明 1.加载完成后swiper指示器导航点&#xff0c;位于显示内容下方。 实现思路 1.将swiper区域分割为两块区域&#xff0c;上方为内容区域&#xff0c;下方为空白区…