android - 安装 Receiver 的 onReceiver 从未被调用

标签 android android-intent broadcastreceiver android-broadcast android-broadcastreceiver

我有一个自定义接收器,可以在安装应用程序时处理 INSTALL_REFERRER Intent 。它在测试期间被调用了一两次,但现在根本没有被调用。我正在使用模拟器进行测试,并已完成 this test documentation 中的说明。向模拟器广播安装 Intent 。我还确保已将我的 Android SDK ADB 连接到模拟器,因此它应该可以接收广播。在终端中,它说我的广播成功了,但是当我从全新安装启动应用程序时,永远不会调用 onReceive。

这是我的接收器的骨架:

public class CustomReceiver extends BroadcastReceiver
{
    @Override
    public void onReceive(Context context, Intent intent)
    {
        //do stuff
        //log stuff
    }
}

这是我的 list :

<receiver
    android:name="path.to.CustomReceiver"
    android:exported="true">
    <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER"/>
    </intent-filter>
</receiver>

我已经尝试从一个新的模拟器开始,以确保它不会将调用列入黑名单,并查看了我能找到的所有关于此的文档和帖子,但似乎没有任何效果。感谢您的帮助。

最佳答案

您引用的文档来自 2013 年。最近的文档建议使用 InstallReferrerReceiver ,专门用于处理该 Intent :

The Google Play com.android.vending.INSTALL_REFERRER Intent is broadcast when an app is installed from the Google Play Store. [InstallReferrerReceiver] listens for that Intent, passing the install referrer data to GTM for Mobile Apps and Google Analytics.

关于android - 安装 Receiver 的 onReceiver 从未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45308951/

相关文章:

使用 WebRTC 的 Android 屏幕共享

android - java.util.NoSuchElementException 导致找不到符号类 DataBindingComponent

java - 网站不会在 android webview 中加载,但在 android 浏览器中工作正常

Android startActivityForResult 在使用相机时向 onActivityResult 返回 null

android - 在同一个应用程序中强制执行 android 权限

android - 如何使用接收器android的 Intent

android - sqlite数据库没有得到更新

android - drawable 目录中的 xml 文件?肯定有什么错误吗?

android - 使用 Intent 删除 ListView 中的项目

java - 在非 Activity 类中注册 BroadcastReceiver