[英]installing apk from a rooted android without user input (grammatically)
I came to know from other related questions and their answers that on a rooted android device we can install an apk without user input, in a similar fashion as google play store might be doing.我从其他相关问题和他们的回答中了解到,在有根的 android 设备上,我们可以在没有用户输入的情况下安装 apk,就像 google play 商店可能正在做的那样。
I have rooted my device and installed my app in the /system/app
folder.我已经植根我的设备并将我的应用程序安装在/system/app
文件夹中。 It appears as a system app now.它现在显示为系统应用程序。 Here is the code I use to install the downloaded apk file这是我用来安装下载的 apk 文件的代码
private void install(UpdateRequest req, Uri apk) {
Intent i;
Log.e("INSTALL PROCESS ", " " + apk.toString());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
i = new Intent(Intent.ACTION_INSTALL_PACKAGE);
i.putExtra(Intent.EXTRA_ALLOW_REPLACE, true);
} else {
i = new Intent(Intent.ACTION_VIEW);
}
i.setDataAndType(apk, "application/vnd.android.package-archive");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}
The above implementation will show install prompt for user.上面的实现将为用户显示安装提示。 I want the app to install without user prompt.我希望在没有用户提示的情况下安装该应用程序。 How can I achieve that?我怎样才能做到这一点?
Add this permission to Manifest:将此权限添加到清单:
<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
Then do:然后做:
try {
String adbCommand = "adb install -r " + fileName;
String[] commands = new String[]{"su", "-c", adbCommand};
Process process = Runtime.getRuntime().exec(commands);
process.waitFor();
} catch (Exception e) {
//Handle Exception
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.