J'essaie d'obtenir les résultats d'une mise à jour APK, à un service. En fait, j'utilise un IntentService, qui fonctionne en arrière-plan. Mon installation est fait par le Service créant une PendingIntent de notification et alors il est reçu dans un BroadcastReceiver qui appelle les éléments suivants:Installer l'APK EXTRA_RETURN_RESULT de IntentService
apkUri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".share", toInstall);
Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
installIntent.setData(apkUri);
installIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
// installIntent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
// installIntent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
installIntent.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME,getApplicationInfo().packageName);
context.startActivity(installIntent);
Le problème semble être que le service n'est pas une activité si je décommenter le EXTRA_RETURN_RESULT I n'obtenez pas de réponse. De plus, je ne peux pas utiliser startActivityForResult car il n'est pas disponible sur un service, seulement une activité.
Pensées?
Ceci est une suite de https://stackoverflow.com/questions/42878709/how-to-install-an-apk-from-service – jbholtz