Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OTA updates for Device Owner Android Application(Kiosk mode)

I am able to make my app, the device owner app through NFC as mentioned here. Now I want to update my app over the air, but I couldn't find a method without rooting.

Google is providing many options for enterprises to develop apps as mentioned here, but nowhere providing a way to update the application through OTA.

Looking for a solution.

like image 863
Shubham Avatar asked Jun 25 '15 05:06

Shubham


2 Answers

This is just pure speculation as I've never tried to use the package installer API myself:

You could try to set an installer package for your device owner app (using PackageManager.setInstallerPackageName()). This installer package would need to be a separate APK signed with the same certificate as the device owner APK.

getPackageManager().setInstallerPackage("<device.owner.package.name>", "<installer.package.name>");

From your installer APK, you could then use PackageInstaller to prepare an update:

PackageInstaller pi = getPackageManager().getPackageInstaller();
int sessId = pi.createSession(new PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL));
PackageInstaller.Session session = pi.openSession(sessId);
OutputStream out = session.openWrite("app");
// .. write updated APK file to out
session.fsync(out);
session.commit(...);
session.close();

I'm not sure if this silently installs your update though (or if that works at all in the way I would have expected).

like image 128
Michael Roland Avatar answered Sep 21 '22 07:09

Michael Roland


Create a service to background check for update. if update available download apk file and write it on some where like sdcard. wait some seconds to write completely flush. then call following code to install your new apk.

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
startActivity(intent);

fileName is path of your new apk file on sd card.

like image 40
ramin eftekhari Avatar answered Sep 19 '22 07:09

ramin eftekhari