1010import android .net .Uri ;
1111import android .os .Build ;
1212import android .os .Environment ;
13+ import android .provider .Settings ;
14+ import android .widget .Toast ;
15+
1316import androidx .core .content .FileProvider ;
1417import androidx .appcompat .app .AlertDialog ;
1518
@@ -36,17 +39,22 @@ public class AppUtils {
3639 */
3740 public static void installApkFile (Context context , File file ) {
3841 // Android 8.0及以上版本需要检查REQUEST_INSTALL_PACKAGES权限
39- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
40- if (!context .getPackageManager ().canRequestPackageInstalls ()) {
41- // 没有安装权限,需要引导用户开启
42- return ;
43- }
44- }
45-
42+ // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
43+ // if (!context.getPackageManager().canRequestPackageInstalls()) {
44+ // // 没有安装权限,需要引导用户开启
45+ // // 跳转到 "安装未知应用" 设置页面
46+ // Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES);
47+ // intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
48+ // intent.setData(Uri.parse("package:"+context.getPackageName()));
49+ // context.startActivity(intent);
50+ // return;
51+ // }
52+ // }
53+
4654 Intent intent = new Intent (Intent .ACTION_VIEW );
4755 intent .addFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
4856 Uri uri = null ;
49-
57+
5058 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
5159 // Android 7.0及以上使用FileProvider
5260 uri = FileProvider .getUriForFile (context , context .getPackageName () + ".fileprovider" , file );
@@ -55,15 +63,15 @@ public static void installApkFile(Context context, File file) {
5563 } else {
5664 uri = Uri .fromFile (file );
5765 }
58-
66+
5967 intent .setDataAndType (uri , "application/vnd.android.package-archive" );
60-
68+
6169 // 添加Android 15兼容性检查
6270 if (Build .VERSION .SDK_INT >= 35 ) {
6371 // Android 15特定的处理
6472 intent .addFlags (Intent .FLAG_ACTIVITY_CLEAR_TOP );
6573 }
66-
74+
6775 if (context .getPackageManager ().queryIntentActivities (intent , 0 ).size () > 0 ) {
6876 context .startActivity (intent );
6977 }
@@ -83,7 +91,7 @@ public static int dp2px(float dpValue) {
8391 *
8492 * @return
8593 */
86- public static String getAppLocalPath (Context context ,String versionName ) {
94+ public static String getAppLocalPath (Context context , String versionName ) {
8795 // apk 保存名称
8896 String apkName = AppUtils .getAppName (AppUpdateUtils .getInstance ().getContext ());
8997 return getAppRootPath (context ) + "/" + apkName + "_" + versionName + ".apk" ;
@@ -97,7 +105,7 @@ public static String getAppLocalPath(Context context,String versionName) {
97105 public static String getAppRootPath (Context context ) {
98106 //构建下载路径
99107 String packageName = AppUpdateUtils .getInstance ().getContext ().getPackageName ();
100- return context .getExternalCacheDir ()+ "/" + packageName + "/apks" ;
108+ return context .getExternalCacheDir () + "/" + packageName + "/apks" ;
101109 }
102110
103111 /**
0 commit comments