Reputation: 103
This question might have been asked earlier, but could not get any clear answer. I basically do not want and client interactions with the updates and other stuff, all they can see is the app running and they are happy. But for this to do I need some background thread or something that checks the market for a new update and updates it in the behind and after applying the update reboot the app.
P.S. I am totally new to android development so really sorry if I am sounding crazy, but this is my requirement
Upvotes: 2
Views: 3277
Reputation: 31
AFAIK, it is possible if you have root access, the process is like following:
/system/app
folder (as a system app)You need following permissions:
android.permission.INSTALL_PACKAGES
android.permission.DELETE_PACKAGES
android.permission.CLEAR_APP_CACHE
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.MOUNT_UNMOUNT_FILESYSTEMS
Your app must be signed with system signature
java -jar signapk.jar platform.x509.pem platform.pk8 helloworld.apk hello.apk
Check for updates in a background thread and download updated .apk file to a temporary place, e.g apk_path
Execute pm install apk_path
command programmatically, below is a snippet:
public String silentInstallation(String apkPath)
{
String[] args = { "pm", "install", "-r", apkPath };
ProcessBuilder processBuilder = new ProcessBuilder(args);
Process process = null;
InputStream errIs = null;
InputStream inIs = null;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int read = -1;
process = processBuilder.start();
errIs = process.getErrorStream();
while ((read = errIs.read()) != -1) {
baos.write(read);
}
baos.write('\n');
inIs = process.getInputStream();
while ((read = inIs.read()) != -1) {
baos.write(read);
}
byte[] data = baos.toByteArray();
result = new String(data);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (errIs != null) {
errIs.close();
}
if (inIs != null) {
inIs.close();
}
} catch (IOException e) {
e.printStackTrace();
}
if (process != null) {
process.destroy();
}
}
return result;
}
Hope it helps.
Upvotes: 3
Reputation: 14274
You can not update (or install) an app without user-interaction, unless
Further, there is no official API available to check the version of an app available in the Google Play store.
You can achieve some of what you are trying to do by keeping track of the current version outside of Google Play and then prompting to update the user by launching the market link. If you do that from a secondary app, you can even wait for the update to be complete and then re-launch the app.
In practice, you can't do silent installs/updates without user-interaction, and that's a Good Thing (tm), for the reasons that the first couple of commenters have stated.
Upvotes: 3