问题
I need to have a mechanism where an app auto-updates itself without any user interaction. The app is an off the shelf app (off market). Updates should happen in background without any click. How can we achieve this?
回答1:
This is not possible, except perhaps on rooted devices or via your own custom ROM. Apps cannot install or update any apps (their own app or the apps of others) without user involvement.
回答2:
this is possible, and don't need to be rooted. You only need to have a signed apk, and execute it in background.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(externalStorageDir, dir+ "APP.apk")),"application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
The user will be prompted while installing, because we should inform the privileges of the app.
回答3:
Solved this issue. Final solution was it cannot be done phones which are not rooted. On rooted phone we can run adb script to do so. While on un rooted phone we can download the apk in background and launch the installer activity that will ask user to click once to approve installing the apk.
来源:https://stackoverflow.com/questions/30101991/auto-update-android-app