Install APK EXTRA_RETURN_RESULT from IntentService

风流意气都作罢 提交于 2019-12-12 05:27:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!