Android(安卓)7.0版本升级解析包错误
16lz
2021-12-21
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath()公有绝对路径
下载:
private void downLoadNewVersion() { OkHttpUtils.get() .url(url) .headers(PackOkHttpUtils.getHeadsMap(this)) .tag(MainActivity.class) .addParams("version", CommonParamsUtil.getVersion(getApplicationContext())) .build() .execute(new FileCallBack(Environment.getExternalStoragePublicDirectory (Environment.DIRECTORY_DOWNLOADS).getAbsolutePath(), "ypw.apk") { @Override public void inProgress(float progress, long total, int id) { super.inProgress(progress, total, id); int progressInt = (int) (progress * 100); progressDialog.setProgress(progressInt); } @Override public void onError(Call call, Exception e, int id) { MyToast.showMessage("下载失败"); List activities = ((MyAppLication) getApplication()).getActivities(); for (AppCompatActivity activity : activities) { activity.finish(); } } @Override public void onResponse(File response, int id) { SPUtils.putBoolean("VersionUpdate", false); progressDialog.dismiss(); Uri uri = Uri.fromFile(response); Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {//7.0系统 uri = FileProvider.getUriForFile (MainActivity.this, "com.youpinwallet.ypw.provider", response); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);//添加这一句表示对目标应用临时授权该Uri所代表的文件 } intent.setDataAndType(uri, "application/vnd.android.package-archive"); startActivity(intent); } });}
AndroidManifest.xml
android:name="android.support.v4.content.FileProvider" android:authorities="自己的包名.provider" android:exported="false" android:grantUriPermissions="true"> android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" />
<?xml version="1.0" encoding="utf-8"?>path="" name="camera_photos" />
更多相关文章
- 运行Android(安卓)Studio时,APP安装失败--Installation failed wi
- Android文件下载进度条的实现
- android 7.0+下载安装
- Android版本更新代码
- Android开发环境搭建
- android studio 56 下载网络歌曲 代码
- Android(安卓)CTS Verifier Sensor Test Cases (1)
- AndroidStudio使用NDK报错显示mips64el-linux-android-strip''
- ndk 历史版本下载