[英]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.