java - Ionic 2 地理围栏上的后台服务不会触发
问题描述
我正在开发一个需要地理围栏在后台运行的 Ionic 应用程序。我正在使用cordova-plugin-geofence插件。我了解 JavaScript 不在后台运行,并且插件开发人员提供了本机代码来收听地理围栏转换。
我按照说明进行操作,但似乎不起作用。关闭应用程序时不会触发转换。
这是我的包名:io.ionic.pla
.
我将此代码放在我的 Android 清单中
<receiver android:name="io.ionic.pla.TransitionReceiver">
<intent-filter>
<action android:name="com.cowbell.cordova.geofence.TRANSITION" />
</intent-filter>
</receiver>
这是我的 TransitionReceiver.java
package io.ionic.pla;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.cowbell.cordova.geofence.Gson;
import com.cowbell.cordova.geofence.GeoNotification;
public class TransitionReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String error = intent.getStringExtra("error");
if (error != null) {
//handle error
Log.println(Log.ERROR, "YourAppTAG", error);
} else {
String geofencesJson = intent.getStringExtra("transitionData");
Log.println(Log.INFO, "xxxYourAppTAG", geofencesJson);
GeoNotification[] geoNotifications = Gson.get().fromJson(geofencesJson, GeoNotification[].class);
//handle geoNotifications objects
}
}
}
请帮助大家,我真的需要这个工作。
解决方案
推荐阅读
- python - 如何在通过程序执行系统/shell/OS 命令后保持程序的 Python 命令行运行
- r - 如何从 R Markdown 关闭 html 文档的 url 打印
- javascript - 谷歌折线图不显示引导模式内的 Y 轴标签
- spring - 在 Spring Application 中使用 Thymeleaf 显示多对多关系数据
- amazon-web-services - 自动向 AWS 中的目标组注册目标
- c - C在没有括号的情况下获取元素
- amazon-web-services - 如何获得发送到一组 Cloudwatch 日志组的兆字节总和?
- excel - VBA - 根据几个条件为工作表行分配唯一 ID
- php - Firefox 仅通过 php 读取 pdf 一次
- java - 无法使用 XML 配置运行第一个 spring 程序。我收到此错误