简体   繁体   English

从 Google Play 商店安装应用程序时的 onActivityResult 回调

[英]onActivityResult callback when installing an app from Google Play Store

I guess the short question is: Is it possible to get a working callback with onActivityResult after installing / not installing an app from Google Play Store?我想简短的问题是:在从 Google Play 商店安装/不安装应用程序后,是否可以通过 onActivityResult 获得工作回调?

I can send the user to an app (assuming they have Google Play Store and using the package name in the url) with:我可以将用户发送到一个应用程序(假设他们有 Google Play 商店并在 url 中使用包名称):

Intent marketIntent = new Intent(Intent.ACTION_VIEW,
        Uri.parse("market://details?id=" + appPackageName));
marketIntent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
startActivityForResult(marketIntent, 1);

I would like to get the result here:我想在这里得到结果:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 1) {
        if (resultCode == RESULT_OK) {
            Log.d("TAG", "onActivityResult: user accepted the install");
        } else if (resultCode == RESULT_CANCELED) {
            Log.d("TAG", "onActivityResult: user cancelled the install");
        } else if (resultCode == RESULT_FIRST_USER) {
            Log.d("TAG", "onActivityResult: failed to install");
        }
    }
}

I would prefer to use Intent.ACTION_INSTALL_PACKAGE rather than an Intent.ACTION_VIEW for the installation, but information regarding how to use the former is limited.我更愿意使用Intent.ACTION_INSTALL_PACKAGE而不是Intent.ACTION_VIEW进行安装,但有关如何使用前者的信息有限。 However, Intent.ACTION_INSTALL_PACKAGE appears to be deprecated from API level 29, so I accept solutions that use PackageInstaller too.但是, Intent.ACTION_INSTALL_PACKAGE似乎从 API 级别 29 开始被弃用,所以我也接受使用PackageInstaller解决方案。

By the way, the code I posted is flawed because it always returns resultCode == RESULT_CANCELED when returning to the app.顺便说一句,我发布的代码有缺陷,因为它在返回应用程序时总是返回resultCode == RESULT_CANCELED

One Possible solution is you have to programatically check with below method for the particular package Name before redirecting user to playstore that whether the app is installed or not.And then in OnActivityResult callback again check it with below method.一种可能的解决方案是,在将用户重定向到 Playstore 之前,您必须以编程方式检查特定包名称的以下方法。然后在 OnActivityResult 回调中再次使用以下方法检查它。

private boolean isAppInstalled(String packageName) {
    PackageManager pm = getPackageManager();
        try {
            pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
            return pm.getApplicationInfo(packageName, 0).enabled;
        }
        catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return false;
        }
    }

Simple Answer is - NO, it's not possible简单的答案是 -不,这是不可能的

You cannot get callback if the user you redirected, installed the application如果您重定向的用户安装了应用程序,您将无法获得回调

I am not aware of your exact use case here, but if it involve work related to referral then i suggest you to look here .我不知道你在这里的确切用例,但如果它涉及与推荐相关的工作,那么我建议你看这里 Google Play Install Referrer can provide information Google Play Install Referrer 可以提供信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Google Play商店安装应用后,应用崩溃 - App crashes after installing app from Google Play Store 在64位Android设备上从Google Play商店安装应用时,如果该应用支持,该应用是否以64位安装? - When installing an app from the Google Play store on a 64-bit Android device, does the app install as 64-bit if the app supports it? 从Play商店安装应用时,拆分APK丢失 - Split APK missing when installing app from Play Store 从 Play 商店安装应用程序后尝试使用 google 登录时,出现“使用 Google 进行身份验证时出错:未知”异常。 查看详细信息 - Getting 'Error authenticating with Google: unknown' exception when trying to signin with google after installing app from play store. See details 从Google Play网站安装应用程序时未传递推荐值 - Referral Value is not passing when installing app from Google play site 从 Google Play 安装应用程序时出错 - Getting error when installing app from Google Play 从Google Play安装应用时收到错误代码-505 - When installing app from google play getting error code -505 应用程序未从 Play 商店安装在某些设备中 - App not installing in some devices from play store 从Google Play商店下载应用时,getInstallerPackageName()是否可能为null? - Is it possible that getInstallerPackageName() is null when app downloaded from Google Play Store? 从Google Play下载应用程序时存储客户数据 - Store Customer data when app is downloaded from google play
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM