定制的 Android 10 系统下,有系统源码,在一个非系统 App 里会调用一个自己开发的库,通过这个库去调用里面的安装 apk 的接口 install ,但是一直报下面的错误,网上有些资料是说可以把 PackageInstaller.apk 这个 app 放到系统里,这样可以绕过安卓 10 的限制,如果此 app 是系统级 app ,那肯定可以安装,之前有做过。
想请教有没有别的办法可以让非系统 app 安装 apk ,有示例最好了,感谢大佬们。
库接口:
public static boolean install(Context context, String filePath) { Intent i = new Intent(Intent.ACTION_VIEW); File file = new File(filePath); if (!file.exists() || !file.isFile() || file.length() <= 0) { return false; } i.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive"); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); return true;
}
错误:
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///sdcard/gime.apk typ=application/vnd.android.package-archive flg=0x10000000 } at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2058) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1716) at android.app.ContextImpl.startActivity(ContextImpl.java:957) at android.app.ContextImpl.startActivity(ContextImpl.java:928) at android.content.ContextWrapper.startActivity(ContextWrapper.java:383) at com.eight.touchoneframework.util.PackageUtils.install(PackageUtils.java:76)