簡體   English   中英

我想要安裝APK Android的Call Receiver

[英]I want Call Receiver on Install of apk android

我想在安裝APK時調用接收器並獲取它的Referrer,我已嘗試執行此操作,這是我的接收器類代碼:

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
}}

這是清單類:

    <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>

嘗試以下代碼:

     <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>

在清單文件中:

<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+上,您無法在清單中注冊這些廣播。

檢查此以獲取更多詳細信息: 鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM