[英]How to check installed application using googlePlay or not in android device
如何检查是否已从Google Play商店(单击“安装”按钮)或下载的.apk文件安装了任何android应用程序并将其安装在设备中?
When installed from Google Play, you will receive a com.android.vending.INSTALL_REFERRER
broadcast during the install process. 从Google Play安装后,您会在安装过程中收到
com.android.vending.INSTALL_REFERRER
广播。 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. 只需为此创建一个广播接收器 ,并在
fromGooglePlay
的行中的SharedPreferences
具有一个布尔值,您可以在接收器fromGooglePlay
其设置为true。
However, I do not think you can have similar receivers for other app stores, like Amazon's. 但是,我认为您无法为其他应用程序商店(如亚马逊)提供类似的接收器。
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. 此外,这在Android 3.1及更高版本上将不起作用,因为尚未启动至少一次的应用程序没有资格接收广播。
However, you can try an alternate solution: 但是,您可以尝试其他解决方案:
In you app, have a constant boolean somewhere, something like GOOGLE_PLAY_BUILD
. 在您的应用中,某处有一个常量布尔值,例如
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
. 为Google Play构建apk时,请将其设置为
true
;为进行手动分发而构建apk时,请将其设置为false
。 Then simply check it's value at runtime, and act accordingly. 然后只需在运行时检查它的值,然后采取相应措施即可。
Also, there is a getInstallerPackageName() method in PackageManager
which can be used for this purpose. 另外,
PackageManager
有一个getInstallerPackageName()方法可用于此目的。 However, this value is not reliable and may be tampered with. 但是,此值不可靠,可能会被篡改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.