mirror of
https://gitee.com/willfree/min-vpn-client_v2.git
synced 2026-10-04 19:42:00 +08:00
版本回退到2.0.4,解决了下载成功但安装失败的问题(FileProvider)
This commit is contained in:
1 parent
b159c75524
commit
6b7e586422
5 files changed
+105
-14
No files matched your search
+1
-1
@@ -43,7 +43,7 @@ android {
|
||||
minSdkVersion 24
|
||||
targetSdkVersion 30
|
||||
versionCode 2
|
||||
versionName "2.0.5"
|
||||
versionName "2.0.4"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
|
||||
@@ -15,6 +15,15 @@
|
||||
android:theme="@style/AppTheme"
|
||||
android:largeHeap="true"
|
||||
tools:ignore="GoogleAppIndexingWarning">
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="com.pkusz.min_vpn_client.android7.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
<!-- <uses-library android:name="com.google.android.things" />-->
|
||||
<activity android:name=".activity.welcome.WelcomeActivity">
|
||||
<intent-filter>
|
||||
@@ -66,6 +75,7 @@
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||
<uses-permission
|
||||
android:name="android.permission.READ_PRIVILEGED_PHONE_STATE"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
@@ -26,7 +27,11 @@ import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
import static com.blankj.utilcode.util.ActivityUtils.startActivity;
|
||||
|
||||
/** 参考链接:https://github.com/ssyandroid/UpdateAppUtils
|
||||
* https://www.jianshu.com/p/bce6a4c779dd
|
||||
* https://blog.csdn.net/wl724120268/article/details/107351169
|
||||
* UpdateAppUtils 更新版本
|
||||
* <p/>
|
||||
* 注意需要存储读写权限与联网权限
|
||||
@@ -353,20 +358,28 @@ public class UpdateAppUtils {
|
||||
try {
|
||||
long totalSize;// 文件总大小
|
||||
long downloadCount = 0;// 已经下载好的大小
|
||||
String path;
|
||||
// String path;
|
||||
// 下载apk,并且安装
|
||||
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||
path = ct.getExternalFilesDir(null) + "/apk";
|
||||
} else {
|
||||
path = ct.getFilesDir() + "/apk";
|
||||
}
|
||||
// if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||
// path = ct.getExternalFilesDir(null) + "/apk";
|
||||
// } else {
|
||||
// path = ct.getFilesDir() + "/apk";
|
||||
// }
|
||||
|
||||
File filePath = new File(path);
|
||||
// File filePath = new File(path);
|
||||
// if (!filePath.exists() || !filePath.isDirectory()) {
|
||||
// filePath.mkdirs();
|
||||
// }
|
||||
|
||||
// file对象,注意路径要和resource xml里配置的一样
|
||||
File apkPath = new File(Environment.getExternalStorageDirectory()+File.separator+"myapk", "app.apk");
|
||||
String path=Environment.getExternalStorageDirectory()+File.separator+"myapk";
|
||||
File filePath=new File(path);
|
||||
if (!filePath.exists() || !filePath.isDirectory()) {
|
||||
filePath.mkdirs();
|
||||
}
|
||||
|
||||
File apkPath = new File(filePath, "app.apk");
|
||||
// File apkPath = new File(filePath, "app.apk");
|
||||
if (!apkPath.exists()) {
|
||||
apkPath.createNewFile();
|
||||
}
|
||||
@@ -456,10 +469,48 @@ public class UpdateAppUtils {
|
||||
* @param t File
|
||||
*/
|
||||
private void installAPK(File t) {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction("android.intent.action.VIEW");
|
||||
intent.addCategory("android.intent.category.DEFAULT");
|
||||
intent.setDataAndType(Uri.fromFile(t), "application/vnd.android.package-archive");
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
System.out.println("第一种安装");
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
intent.setDataAndType(getUriForFile(this.ct, t), "application/vnd.android.package-archive");
|
||||
} else {
|
||||
System.out.println("第二种安装");
|
||||
intent.setDataAndType(Uri.fromFile(t), "application/vnd.android.package-archive");
|
||||
}
|
||||
System.out.println("安装完成: "+t.getAbsolutePath());
|
||||
ct.startActivity(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取合适的File Uri
|
||||
* @param context
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static Uri getUriForFile(Context context, File file) {
|
||||
Uri fileUri = null;
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
fileUri = getUriForFile24(context, file);
|
||||
} else {
|
||||
fileUri = Uri.fromFile(file);
|
||||
System.out.println("fileurl: "+fileUri);
|
||||
}
|
||||
return fileUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取File Uri from 安卓7及以上版本
|
||||
* @param context
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static Uri getUriForFile24(Context context, File file) {
|
||||
Uri fileUri = androidx.core.content.FileProvider.getUriForFile(context,
|
||||
"com.pkusz.min_vpn_client.android7.fileprovider",
|
||||
file);
|
||||
System.out.println("fileurl24: "+fileUri);
|
||||
return fileUri;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
android:layout_marginLeft="@dimen/dp_20"
|
||||
android:layout_marginRight="@dimen/dp_0"
|
||||
android:padding="5dp"
|
||||
android:text="v2.0.5"
|
||||
android:text="v2.0.4"
|
||||
android:textColor="@color/color_bg_name"
|
||||
android:textSize="17.5dp"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths>
|
||||
<!-- <external-path-->
|
||||
<!-- name="external_storage_root"-->
|
||||
<!-- path="" />-->
|
||||
<!-- <files-path-->
|
||||
<!-- name="files-path"-->
|
||||
<!-- path="." />-->
|
||||
<!-- <cache-path-->
|
||||
<!-- name="cache-path"-->
|
||||
<!-- path="." />-->
|
||||
<!-- <!–/storage/emulated/0/Android/data/...–>-->
|
||||
<!-- <external-files-path-->
|
||||
<!-- name="external_file_path"-->
|
||||
<!-- path="." />-->
|
||||
<!-- <!–代表app 外部存储区域根目录下的文件 Context.getExternalCacheDir目录下的目录–>-->
|
||||
<!-- <external-cache-path-->
|
||||
<!-- name="external_cache_path"-->
|
||||
<!-- path="." />-->
|
||||
<!--配置root-path。这样子可以读取到sd卡和一些应用分身的目录,否则微信分身保存的图片,
|
||||
就会导致 java.lang.IllegalArgumentException: Failed to find configured
|
||||
root that contains /storage/emulated/999/tencent/MicroMsg/WeiXin/expo
|
||||
rt1544062754693.jpg,在小米6的手机上微信分身有这个crash,华为没有 -->
|
||||
<root-path
|
||||
name="root-path"
|
||||
path="" />
|
||||
<external-path
|
||||
name="myAPK"
|
||||
path="myapk"/>
|
||||
</paths>
|
||||
Reference in new issue
Block a user