【问题标题】:Awareness API global receiver intent filterAwareness API 全局接收者意图过滤器
【发布时间】:2016-10-19 09:06:47
【问题描述】:

我正在一个 android 应用程序中实现 google Awareness API,但没有任何示例或指南显示如何在应用程序关闭或在后台收听 api 事件。 我根据答案here写了一个全局接收器

    <receiver android:name=".MyFenceReceiver" >
   <intent-filter>
     <action android:name="android.intent.action.FENCE_RECEIVER_ACTION" />
    </intent-filter>
</receiver>

但是,由于它不起作用,我怀疑我不知道用于拦截 Awarness 事件的正确意图过滤器。 有谁知道正确的意图过滤器,或者如果这不是我的问题,我如何在应用程序关闭或使用全局接收器在后台拦截 API 事件?

【问题讨论】:

    标签: android intentfilter android-broadcastreceiver google-awareness


    【解决方案1】:

    好的,所以最终的答案是你必须在清单中注册这个接收器并给它你自己的意图过滤器,如下所示:

       Intent intent = new Intent(Constants.Requests.FENCE_RECEIVER_ACTION);
                        mPendingIntent =
                                PendingIntent.getBroadcast(BaseActivity.this, 0, intent, 0);
    
                        // The broadcast receiver that will receive intents when a fence is triggered.
    

    “FENCE_RECEIVER_ACTION”在哪里:

    // The intent action which will be fired when your fence is triggered.
        public final static String FENCE_RECEIVER_ACTION =
                BuildConfig.APPLICATION_ID + "FENCE_RECEIVER_ACTION";
    

    在清单中你像这样放入接收器:

     <receiver android:name=".FenceReceiver" >
            <intent-filter>
                <action android:name="'YOUR_PACKGE_NAME_HERE'FENCE_RECEIVER_ACTION" />
            </intent-filter>
        </receiver>
    

    无需在任何地方注销接收器。

    【讨论】:

    • 用了你的方法。当应用程序处于前台时工作,当我按下主页按钮并且应用程序不再处于前台时也工作。但是,当我从最近的应用程序列表中关闭该应用程序时,它不再起作用。任何想法如何让它在应用程序关闭时仍然工作?即触发器启动应用程序或其他什么?
    • @AyoMakanjuola,你知道怎么做吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-01
    • 2016-11-06
    • 1970-01-01
    • 2014-09-20
    • 1970-01-01
    • 2021-11-30
    • 2019-06-11
    相关资源
    最近更新 更多