从IntentService安装APK EXTRA_RETURN_RESULT[英] Install APK EXTRA_RETURN_RESULT from IntentService

本文是小编为大家收集整理的关于从IntentService安装APK EXTRA_RETURN_RESULT的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正在尝试将结果从APK更新获取到服务.实际上,我使用的是在后台运行的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);

问题似乎是该服务不是一项活动,因此,如果我取消extra_return_result,我将不会得到响应.另外,我不能使用StartActivityForresult,因为它在服务上不可用,而是一项活动.

想法?

推荐答案

对于以下其他人来说.我最终让我的Intentservice启动了一项我创建的活动,我可以使用" android:them ="@android:style/theme.translucent.notitlebar"",然后我可以执行StartactivityForresults.然后以广播意图发送结果

本文地址:https://www.itbaoku.cn/post/1938014.html

问题描述

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?

推荐答案

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