简体   繁体   English

我想要安装APK Android的Call Receiver

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

All I want to call receiver on install of APK and get Referrer of it, I have tried to do this, here is my code of receiver class: 我想在安装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
}}

And here is the 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>

try following code: 尝试以下代码:

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

in manifest file: 在清单文件中:

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

and in java code : 并在Java代码中:

IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
        intentFilter.addAction(Intent.ACTION_PACKAGE_INSTALL);
        intentFilter.addDataScheme("package");
        registerReceiver(br, intentFilter);

this will work 7.1 and below devices .On Android 8.0+, you cannot register for those broadcasts in the manifest. 这将在7.1及以下版本的设备上运行。在Android 8.0+上,您无法在清单中注册这些广播。

Check this for more detail: link 检查此以获取更多详细信息: 链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM