如何检测如果一个特定的应用程序正在下载/安装了谷歌Play商店? [英] How to detect if a specific app is being downloaded/installed by the Google Play store?

查看:283
本文介绍了如何检测如果一个特定的应用程序正在下载/安装了谷歌Play商店?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多应用程序提供建议安装由开发商或开发商的合作伙伴提出的申请。这些建议只是链接到推荐的应用程序可以从安装Play商店。

我不想为X程序的建议,如果:

  • 在已安装应用程序X
  • 应用X是正在安装的程序(例如,下载的谷歌播放)

如果是装X检测很容易,但我似乎无法找到任何API来读取下载/从谷歌播放安装状态。有什么方法来检测,如果用户在安装应用程序X的过程?

解决方案
  

有什么方法来检测,如果用户是在安装过程中   X程序?

你会得到这个最接近的是通过使用<一个href="https://developer.android.com/reference/android/service/notification/NotificationListenerService.html"相对=nofollow> NotificationListenerService

从文档:

  

这是接收来自系统调用时,新通知服务   张贴或删除。

但考虑到该服务在API级别18是最近加入你的使用情况,您可以考虑使用的BroadcastReceiver 和监听时 android.intent.action.PACKAGE_ADDED android.intent.action.PACKAGE_REMOVED 被调用。这样,一旦一个应用程序被安装或删除,你可以做你想做的与包的名称,如提供一个链接到Play商店。

下面是一个例子:

的BroadcastReceiver

 公共类PackageChangeReceiver扩展的BroadcastReceiver {

    @覆盖
    公共无效的onReceive(上下文的背景下,意图意图){
        如果(意向== NULL || intent.getData()== NULL){
            返回;
        }

        最后弦乐的packageName = intent.getData()getSchemeSpecificPart()。
        //做一些与包名称
    }

}
 

AndroidManifest

 &LT;接收器的Andr​​oid版本:NAME =your_path_to.PackageChangeReceiver&GT;
    &LT;意向滤光器&gt;
        &lt;作用机器人:名称=android.intent.action.PACKAGE_ADDED/&GT;
        &lt;作用机器人:名称=android.intent.action.PACKAGE_REMOVED/&GT;

        &lt;数据机器人:计划=包/&GT;
    &所述; /意图滤光器&gt;
&LT; /接收器&GT;
 

Many apps provide recommendations to install other applications made by the developer or developer's partners. The recommendations are just links to the Play Store where the recommended app may be installed from.

I don't want to provide a recommendation for app X if:

  • App X is already installed
  • App X is in the process of being installed (e.g. downloading on Google Play)

Detecting if X is installed is easy, but I can't seem to find any API to read downloading/installing state from Google Play. Is there any way to detect if the user is in the process of installing app X?

解决方案

Is there any way to detect if the user is in the process of installing app X?

The closest you'll get to this is by using a NotificationListenerService.

From the docs:

A service that receives calls from the system when new notifications are posted or removed.

But considering this Service was recently added in API level 18 and your use case, you might consider using a BroadcastReceiver and listening for when android.intent.action.PACKAGE_ADDED and android.intent.action.PACKAGE_REMOVED are called. This way once an app is installed or removed, you can do what you want with the package name, like provide a link to the Play Store.

Here's an example:

BroadcastReceiver

public class PackageChangeReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent == null || intent.getData() == null) {
            return;
        }

        final String packageName = intent.getData().getSchemeSpecificPart();
        // Do something with the package name
    }

}

In your AndroidManifest

<receiver android:name="your_path_to.PackageChangeReceiver" >
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_ADDED" />
        <action android:name="android.intent.action.PACKAGE_REMOVED" />

        <data android:scheme="package" />
    </intent-filter>
</receiver>

这篇关于如何检测如果一个特定的应用程序正在下载/安装了谷歌Play商店?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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