I have created a device owner app. It can turn an app installed already into Kiosk Mode, I am trying to update the kiosk app remotely, not from playstore, but it's not getting updated. Could anyone please help me with some pointers?
Asked
Active
Viewed 1,561 times
0
-
Is the app you want to update on Play? If yes you will need to use one of Google's API to manage updates. The Android Management API allows to set a [SystemUpdate](https://developers.google.com/android/management/reference/rest/v1/enterprises.policies#SystemUpdate) window to control when app and system updates happen. – Fred Nov 10 '17 at 13:58
-
@Fred, thanks for the response, but I want to update it remotely. – rcde0 Nov 10 '17 at 14:00
-
Create your own server add your apk over there than download apk from your server and install using adb command but it needed root device. – Upendra Shah Nov 10 '17 at 14:14
-
The Android Management API allows you to do everything remotely, it's a Cloud API. – Fred Nov 10 '17 at 17:05
-
@UpendraShah, no the device is not rooted. – rcde0 Nov 12 '17 at 14:43
-
Okay, So there is another way to install app using intent but is need user interactions. – Upendra Shah Nov 15 '17 at 05:49
-
@UpendraShah, Could you please be more descriptive, Thanks. – rcde0 Nov 15 '17 at 07:29
1 Answers
1
You have to host your apk on your server and then download it based on any conditions that you specify. You can then use this code to update your app.
public static boolean InstallAPK(Context context, String apk_file_name) {
try {
File apkfile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + apk_file_name);
if (apkfile.exists()) {
FileInputStream in = new FileInputStream(apkfile);
PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller();
PackageInstaller.SessionParams params = new PackageInstaller.SessionParams(
PackageInstaller.SessionParams.MODE_FULL_INSTALL);
params.setAppPackageName(context.getPackageName());
// set params
int sessionId = packageInstaller.createSession(params);
PackageInstaller.Session session = packageInstaller.openSession(sessionId);
OutputStream out = session.openWrite("COSU", 0, -1);
byte[] buffer = new byte[65536];
int c;
while ((c = in.read(buffer)) != -1) {
out.write(buffer, 0, c);
}
session.fsync(out);
in.close();
out.close();
session.commit(createIntentSender(context, sessionId));
return true;
} else
return false;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
private static IntentSender createIntentSender(Context context, int sessionId) {
PendingIntent pendingIntent = PendingIntent.getBroadcast(
context,
sessionId,
new Intent(ACTION_INSTALL_COMPLETE),
0);
return pendingIntent.getIntentSender();
}

Name is Nilay
- 2,743
- 4
- 35
- 77

Nivil Boban
- 286
- 1
- 13
-
-
I tried that code it is not showing any error, it is returning true but apk is not installed? – Suresh Mewara Jan 25 '19 at 11:58