安装APK编程 - 返回值 [英] Install APK programmatically - return value

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

问题描述

在我的应用程序,我打电话从我的活动JavaScript接口。与此接口相关联的web视图,我要求用户下载并安装APK。我使用的是startActivityForResult开始安装过程(下载文件后)。这里是code:

In my app, I am calling a javascript interface from my activity. In the webview associated with this interface, I am asking the user to download and install an APK. I am using a "startActivityForResult" to start the install process (after downloading the file). Here is the code:

Intent promptInstall = new Intent(Intent.ACTION_VIEW);
        promptInstall.setDataAndType(Uri.fromFile(new File(PATH + "app.apk")), "application/vnd.android.package-archive");
        startActivityForResult(promptInstall, ACCEPT_INSTALL);

我使用的onActivityResult中的主要活动课来捕获上述活动的返回值。这里是code:

I am using "onActivityResult" in the main activity class to capture the return value from the above activity. Here is the code:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.d("requestCode, resultCode from Install APK: ", Integer.toString(requestCode) + ", " + Integer.toString(resultCode));   
}

我现在面临的问题是,结果code总是返回0,无论用户是否选择安装应用程序或不安装应用程序。我真的需要知道用户是否安装该应用或不。任何想法,为什么返回值始终为0?

The problem I am facing is that "resultCode" always returns 0, irrespective of whether the user chose to install the app or not install the app. I really need to know whether the user installed the app or not. Any ideas as to why the return value is always 0?

我的最后一招是使用软件包管理系统,以检查在的onActivityResult功能的应用程序的存在,以确定是否安装或没有应用程序,但我想知道为什么返回值始终为0。

My last resort would be to use packagemanager to check for the existence of the app in the onActivityResult function to determine if the app was installed or not, but I would like to know why the return value is always 0.

谢谢了...

推荐答案

我们开发了一个应用程序市场,面对同样的问题。我们的解决方案是使用包管理器来为你建议。

We developed an app market and faced the same problem. Our solution was to use the packet manager as you propose.

我看着一些意向性的过滤器,因为似乎周围的安装过程中的一些意图。但我们并没有能够得到它运行。包经理解决工作正常寿,你可以检查应用程序版本,它在App-更新很重要的。

I looked into some intent-filters as there seem to be some intents around the installation process. But we were not able to get it running. The packet-manager solution works fine tho as you can check the app version which is important on app-updates.

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

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