Android应用内计费只允许一个BroadcastReceiver接收计费广播?

发布于 2024-11-02 01:20:49 字数 225 浏览 0 评论 0原文

我已经让谷歌的示例应用内计费应用程序(地下城)工作得很好。但是,我正在尝试为我正在编写的应用程序注册第二个计费接收器,但我无法这样做。似乎只有我的 AndroidManifest.xml 中声明的第一个接收器才是接收广播的接收器,但第一个接收器之后的任何接收器都不会接收广播。在运行时,我已经使用 isOrderedBroadcast() 确认广播不是有序广播,因此我并没有在某处中止广播(只能中止有序广播)。任何对此的帮助将不胜感激。

I have gotten Google's sample in-app billing app (Dungeons) working just fine. However, I'm trying to register a second billing receiver for an app I'm writing, and I'm unable to do so. It seems as though only the first receiver declared in my AndroidManifest.xml is the one that receives broadcasts, but any following the first one do not receive broadcasts. At run-time, I've confirmed that the broadcast is not an ordered broadcast by using isOrderedBroadcast(), so it's not as though I'm aborting the broadcast somewhere (only ordered broadcasts can be aborted). Any help with this would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄情伤 2024-11-09 01:20:49

也许第一个接收器需要先取消注册,然后第二个接收器才能执行其尝试执行的操作。在您的 Activity 中,重写 onStop() 方法,以便在 Activity 关闭时取消注册广播接收器。这对我来说很有效。

// Import statements go here.

public class MyActivity extends AppCompatActivity implements IabBroadcastReceiver.IabBroadcastListener {

    // Other variables and methods go here.

    // Unregister the receiver when the activity closes.
    @Override
    protected void onStop()
    {
        try {
            unregisterReceiver(YOUR_BROADCAST_RECEIVER_VARIABLE_NAME_HERE);
        } catch (Exception ex) {
            // Uncomment the following for debugging.
            //ex.printStackTrace();
        }

        // Call the original onStop() method.
        super.onStop();
    }
}

Perhaps the first receiver needs to be unregistered before the second one can do what it is trying to do. In your activity, override the onStop() method so that the broadcast receiver is unregistered when the activity closes. This is what has worked for me.

// Import statements go here.

public class MyActivity extends AppCompatActivity implements IabBroadcastReceiver.IabBroadcastListener {

    // Other variables and methods go here.

    // Unregister the receiver when the activity closes.
    @Override
    protected void onStop()
    {
        try {
            unregisterReceiver(YOUR_BROADCAST_RECEIVER_VARIABLE_NAME_HERE);
        } catch (Exception ex) {
            // Uncomment the following for debugging.
            //ex.printStackTrace();
        }

        // Call the original onStop() method.
        super.onStop();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文