我在谷歌上搜索了一个从.apk文件升级的应用程序。这是代码。但什么也没发生。没有错误,只是什么都没有。我在安卓12上进行了测试。
try {
Intent install = new Intent(Intent.ACTION_VIEW);
install.setDataAndType(Uri.parse("content://" + ApkFile_FullPath), "application/vnd.android.package-archive");
install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(install);
} catch (Exception e){
Log.i("aaaaa: ", "intent: " + e.getMessage());
}
AndroidManifest.xml中的权限如下:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CAMERA" />
它甚至可以自我升级吗?
通过4个步骤安装apk的简单解决方案:
-
在AndroidManifest.xml中添加这些权限:代码
-
将其添加到AndroidManifest.xml中的
<application>
标记中:代码 -
在
res
的xml
文件夹中创建一个名为file_paths.xml
的文件:代码 -
使用此方法安装apk文件。:代码
快乐编码!