通过应用考取数据安装后无需启动 [英] Pasing data through app after install without launching

查看:152
本文介绍了通过应用考取数据安装后无需启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

指的<一个href=\"http://stackoverflow.com/questions/30885975/main-app-download-another-app-then-use-it\">this发布我要问别的东西。

我有一个应用程序的A其中下载和安装其他应用程序的B。结果
我想的以转移数据的 A ,然后 A 将使用这些数据做的工作。

我知道,我们可以用意图传输数据。结果
安装的与应用后的 A 的Andr​​oid提供了一个选择,点击OK或启动我的问题是:


  • 是可以从传递数据的 A 当我们点击确定? (因此,我们留在的 A 应用,而无需启动

  • 如果是,如何?那是可能的隐形推出的?我应该怎样code 以获取此comportement?

我知道这可能很难理解,你可以尝试来检查我的previous平局(<一个href=\"http://stackoverflow.com/questions/30885975/main-app-download-another-app-then-use-it\">here再次)。

编辑:

我用这个code推出的从安装的 A

 意向意图=新意图(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
URI URI = Uri.fromFile(新文件(Environment.getExternalStorageDirectory()的toString()+/downloadedfile.apk)。);
Intent.setDataAndType(URI,应用程序/ vnd.android.package归档);
。getApplicationContext()startActivity(意向);


解决方案

有许多方法来处理这​​个问题,这里是一个(我相信)是实现非常简单。由于您的一个应用[presumably]知道它正在安装:

应用程序答:添加广播接收器来应对安装,但默认情况下它是关闭的。

<一个href=\"http://stackoverflow.com/questions/14350460/android-broadcastreceiver-on-application-install-uninstall\">Android:广播接收器上的应用程序安装/卸载

附录二:添加服务后台通信


  

注:服务必须出口是通过明确意图的其他应用程序访问,但是这将创建一个安全的关注,因为它是开放的所有其他应用程序。


当应用程序A的用户点击安装应用程序A:

启动广播接收器设置为检测安装一个过滤器:
<一href=\"http://stackoverflow.com/questions/14350460/android-broadcastreceiver-on-application-install-uninstall\">stackoverflow...android-broadcastreceiver-on-application-install-uninstall

应用程序A开始安装。

在该广播接收器检测软件包被添加(包名称将在收到的意图,),它可以阻止广播接收器,并可以发送的明确意图 命名在APPB服务。你可以通过你的意图需要的任何数据。

当APPB服务接收的意图,它可以在任何你想要的方式行事。

服务使用一个非空的意图始终创建,虽然明确意图 S'行动'为空。
如果该服务被重新创建Service.onStartCommand()可能会收到一个空的意图。

我要填写更多code,但我有一天的工作;)


  

请注意:

   Intent.ACTION_PACKAGE_ADDED 的所谓当安装一个包。

   Intent.ACTION_PACKAGE_INSTALL 是从来没有使用过,并且是德$ p $在API 14 pcated。


http://developer.android.com/reference/android/content/ BroadcastReceiver.html
http://developer.android.com/reference/android/content/Intent.html

Refering to this post I need to ask something else.

I have an application "A" which download and install another app "B".
I want B to "transfer" data to A and then A will use this data to do work.

I know that we can transfer data with intent.
After installing B app with A, Android provide a choice with "Ok" or "Launch" ; my question is :

  • Is that possible to pass data from B to A when we click on "Ok"? (So we stay in A app without launching B)
  • If yes, how? Is that possible to "invisible" launch B? How should I code B to get this comportement?

I know that might be hard to understand, you can try to check my previous draw (here again).

EDIT:

I use this code to launch B installation from A.

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory().toString() + "/downloadedfile.apk"));
Intent.setDataAndType(uri, "application/vnd.android.package-archive");
getApplicationContext().startActivity(intent);

解决方案

There are many ways to handle this, here is one that (I believe) is quite simple to implement. Since your A app [presumably] knows what it is installing:

App A: Add a BroadcastReceiver to react to the installation, though by default it is off.

Android: BroadcastReceiver on application install / uninstall

App B: Add a Service for background communication.

Note: A Service must be exported to be accessible to other apps via explicit intent, but this creates a security concern, as it is open to all other apps.

When a user of App A clicks to install App B:

Start the BroadcastReceiver with a filter set to detect the install: stackoverflow...android-broadcastreceiver-on-application-install-uninstall

App A starts the install.

When the BroadcastReceiver detects the package has been added (the package name will be in the received intent,) it can stop the BroadcastReceiver, and can send an explicit Intent naming the Service in AppB. You can pass whatever data you need in the intent.

When the AppB service receives the intent, it can act in any way you'd like.

Service is always created using a non-null Intent, though the 'action' of explicit Intents is null. Service.onStartCommand() might receive a null Intent if the service was re-created.

I'd fill in more of the code, but I have a day job ;)

Note:
Intent.ACTION_PACKAGE_ADDED called when a package is installed.
Intent.ACTION_PACKAGE_INSTALL was never used, and was deprecated in API 14.

http://developer.android.com/reference/android/content/BroadcastReceiver.html http://developer.android.com/reference/android/content/Intent.html

这篇关于通过应用考取数据安装后无需启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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