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

查看:23
本文介绍了从 IntentService 安装 APK EXTRA_RETURN_RESULT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 APK 更新获取结果到服务.实际上,我使用的是在后台运行的 IntentService.我的安装是由服务为通知创建 PendingIntent 完成的,然后它在调用以下内容的 BroadcastReceiver 中接收:

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);

问题似乎是服务不是活动,所以如果我取消注释 EXTRA_RETURN_RESULT,我不会得到响应.我也不能使用 startActivityForResult 因为它在服务上不可用,只能在活动中使用.

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.

想法?

推荐答案

对于后续的其他人.我最终让我的 IntentService 启动了一个我用android:theme="@android:style/Theme.Translucent.NoTitleBar""创建的活动然后我可以执行 startActivityForResults.然后将结果发送到 Broadcast Intent

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

这篇关于从 IntentService 安装 APK EXTRA_RETURN_RESULT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆