我正在开发一个Android应用程序,用户在安装并运行Play商店中的应用程序时会获得积分。现在,如果用户想要赚取品脱,那么他必须从游戏商店安装一些应用程序...同时从游戏商店安装应用程序应用程序的状态(安装/下载)
在我的Android应用中,我想了解应用的状态。即app正在安装或下载
我发现NotifyListenerservice ...不确定它是否仅适用于此。
请告诉我如何实现这一目标。
谢谢, 安贾尼
答案 0 :(得分:0)
使用BroadcastReceiver查看它是否已安装或删除,或者您想要的任何内容。
<receiver
android:name=".receiver.PackageChangeReceiver"
android:enabled="true">
<intent-filter android:priority="99999998">
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_CHANGED"/>
<action android:name="android.intent.action.PACKAGE_FULLY_REMOVED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<data android:scheme="package" />
</intent-filter>
</receiver>
您可以在Intent PACKAGE_ADDED not registering
找到示例您还可以使用AccessibilityService验证应用程序是否已启动,但您不应滥用此功能。
答案 1 :(得分:0)
否您无法检查..您的应用无法识别已安装或已下载。
只有在手动启动应用程序后才会初始化广播接收器。在那之前,广播接收器实际上没有收听。 应用程序处于停止状态。该应用需要手动启动 ..
答案 2 :(得分:0)
@Anjali您提出的问题称为转化跟踪。您可以在Google上找到有关此术语的更多信息。
当在设备上安装app时,OS会向应用程序发送广播,可以通过应用程序进行监听。看看下面的代码:
@Override
public void onReceive(Context context, Intent intent) {
try {
if (intent.getAction().equals("com.android.vending.INSTALL_REFERRER")) {
Bundle extras = intent.getExtras();
String referrerString = extras.getString("referrer");
//ReferrerString variable contain your data which was passed to your application. Now you can do whatever you want to like communicating with server etc.
}
} catch (Exception e) {
}
}
通常,如果要在url中传递一些唯一参数来安装应用程序,那么您将在ReferrerString中获取这些参数。您的Play商店链接如下所示:
http://play.google.com/store/apps/details?id=packagename的&安培;引荐= yourdata 强>
您需要以下清单条目:
<receiver android:name="packagename.BoradcastReciverImplmentedClass" android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>