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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With