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.
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).
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.
You could use Play Store to provide updates for your app:
Provision device owner app through NFC, just as you already did.
Provide an updated version (same package name, same signature, higher version number) of your device owner app on Play Store.
In the Play Store app on your device, search for your Play Store version of the app and install the update.
Activate auto-updates for your device owner app in Play Store (on the Play Store page of your app, click menu (three dots) and activate the checkbox for auto-update.
That's quite some effort for the provisioning phase, but the device should receive future updates automatically.
I guess you might want to become an EMM/MDM partner app-it is similar to device owner app but with enhanced privileges and APIs. Normally OEMs like Samsung/HTC provides hidden APIs to the MDM partner apps for upgrading apps.I am not sure whether Android for Work also provides this api.
For eg: OEMs provides an api called updatePackage(String packageName) which can be use by MDM client on the device to update the package.You can use this API to update the Device Owner App too.
来源:https://stackoverflow.com/questions/31041832/ota-updates-for-device-owner-android-applicationkiosk-mode