问题
I'm trying to get the results from an APK update, to a Service. Actually I'm using an IntentService, that is running in the background. My install is done by the Service creating a PendingIntent for Notification and then it's received in a BroadcastReceiver which calls the following:
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);
The problem seems to be that the Service is not an Activity so if I uncomment the EXTRA_RETURN_RESULT I do not get a response. Also I cannot use startActivityForResult because it's not available on a Service, only an Activity.
Thoughts?
回答1:
For others that follow. I ended up having my IntentService launching an Activity I created with "android:theme="@android:style/Theme.Translucent.NoTitleBar"" Then I could perform the startActivityForResults. Then send the results in a Broadcast Intent
来源:https://stackoverflow.com/questions/45292278/install-apk-extra-return-result-from-intentservice