所有我想在安装APK时调用接收器并获取它的推荐者,我试图这样做,这是我的接收器类代码:
public class InstallReferrerReceiver extends BroadcastReceiver {
String TAG = "InstallReferrerReceiver";
@Override
public void onReceive(Context context, Intent intent) {
String referrer = intent.getStringExtra("referrer");
Log.d(TAG, "refferer" + referrer);
//Use the referrer
}}
这是Manifest Class:
<receiver
android:name="com.installtracksdk.InstallReferrerReceiver"
android:exported="true"
android:permission="android.permission.INSTALL_PACKAGES">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
答案 0 :(得分:0)
尝试以下代码:
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_CHANGED" />
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>
答案 1 :(得分:0)
:
<receiver android:name=".YourReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<data android:scheme="package"/>
</intent-filter>
并在java代码中:
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
intentFilter.addAction(Intent.ACTION_PACKAGE_INSTALL);
intentFilter.addDataScheme("package");
registerReceiver(br, intentFilter);
这将适用于7.1及以下设备。在Android 8.0+上,您无法在清单中注册这些广播。
查看此内容以获取更多详细信息:link