如何在Android设备上使用Google Play或不检查安装的应用程序 [英] How to check installed application using googlePlay or not in android device

查看:1161
本文介绍了如何在Android设备上使用Google Play或不检查安装的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查,任何Android应用程序从谷歌Play商店安装(点击安装按钮),或者通过下载.apk文件,并在设备安装呢?

How to check that any android application was installed from Google Play Store(by clicking on Install button) or by downloaded .apk file and install it in device ?

推荐答案

在谷歌从安装播放,您将收到在一个 com.android.vending.INSTALL_REFERRER 播出安装过程。简单地<一个href=\"http://n3vrax.word$p$pss.com/2011/07/15/listen-for-install-referrer-broadcast-message-get-referrer-on-install/\"相对=nofollow>创建此广播接收机,并在你的共享preferences一个布尔值沿行 fromGooglePlay ,您可以设置为true,在接收机中。

When installed from Google Play, you will receive a com.android.vending.INSTALL_REFERRER broadcast during the install process. Simply create a broadcast receiver for this, and have a boolean value in your SharedPreferences along the lines of fromGooglePlay, which you can set to true in the receiver.

不过,我不认为你可以有其他应用商店类似的接收器,如Amazon的。

However, I do not think you can have similar receivers for other app stores, like Amazon's.

此外,这不会在Android 3.1及以上的工作,因为尚未推出至少一次应用程序是没有资格接收广播。

Additionally, this will not work on Android 3.1 and above, as apps that have not been launched at least once are not eligible to receive broadcasts.

不过,你可以尝试另一种解决方案:

However, you can try an alternate solution:

在你的应用程序,有一个恒定的布尔地方,像 GOOGLE_PLAY_BUILD 。建立用于谷歌Play上的apk,该设置为真正,并建立了手动分发的APK,将其设置为当。然后,只需检查它的在运行时的价值,并采取相应的行动。

In you app, have a constant boolean somewhere, something like GOOGLE_PLAY_BUILD. When building an apk for Google Play, set this to true, and when building an apk for manual distribution, set this to false. Then simply check it's value at runtime, and act accordingly.

此外,还有一个<一href=\"http://developer.android.com/reference/android/content/pm/PackageManager.html#getInstallerPackageName%28java.lang.String%29\"相对=nofollow> getInstallerPackageName()在软件包管理系统可用于这一目的。但是,该值是不可靠的,并且可以被篡改。

Also, there is a getInstallerPackageName() method in PackageManager which can be used for this purpose. However, this value is not reliable and may be tampered with.

这篇关于如何在Android设备上使用Google Play或不检查安装的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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