我正尝试更新不会发布到Play商店的应用程序,因为该应用程序仅供内部使用,我已经能够下载文件,但是在启动安装意图时却得到了“错误解析包”
-权限:
android:name="android.permission.INTERNET"
android:name="android.permission.ACCESS_NETWORK_STATE"
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:name="android.permission.REQUEST_INSTALL_PACKAGES"
-我已经厌倦的意图代码:
Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE); intent.setData(FileProvider.getUriForFile(StandardListActivity.this, BuildConfig.APPLICATION_ID+".authorityStr",localFile));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
startActivity(intent);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getPackageName().toString())); intent.setDataAndType(FileProvider.getUriForFile(StandardListActivity.this, BuildConfig.APPLICATION_ID+".authorityStr"
,localFile), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Intent installIntent = new Intent(Intent.ACTION_VIEW); installIntent.setDataAndType(FileProvider.getUriForFile(StandardListActivity.this,BuildConfig.APPLICATION_ID+".authorityStr",localFile), "application/vnd.android.package-archive");
installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(installIntent);
-创建用于存储的本地文件:
File rootPath = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "/blee");
if (!rootPath.exists()) {
rootPath.mkdirs();
}
final File localFile = new File(rootPath, "test2.apk");
想知道是否还有其他可以尝试的方法,请请勿重定向,因为我可能已经尝试过了。
谢谢