Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 当用户进入地理围栏或居住在地理围栏中时,应用程序意外关闭_Android_Google Maps_Geofencing - Fatal编程技术网

Android 当用户进入地理围栏或居住在地理围栏中时,应用程序意外关闭

Android 当用户进入地理围栏或居住在地理围栏中时,应用程序意外关闭,android,google-maps,geofencing,Android,Google Maps,Geofencing,我已经在我的android应用程序中实现了Geofence服务,当用户进入、居住或退出该Geofence时通知用户。在我的实现中,通过长按特定位置,我可以在任何地方添加geofence。 但当用户进入Geofence或Geofence被添加时,用户已经在Geofence中,应用程序意外崩溃 我如何解决这个问题 这是我的GeofenceBroadcastReceiver.java类 公共类GeoFenceBroadcastReceiver扩展了BroadcastReceiver{ private

我已经在我的android应用程序中实现了Geofence服务,当用户进入、居住或退出该Geofence时通知用户。在我的实现中,通过长按特定位置,我可以在任何地方添加geofence。 但当用户进入Geofence或Geofence被添加时,用户已经在Geofence中,应用程序意外崩溃

我如何解决这个问题

这是我的GeofenceBroadcastReceiver.java

公共类GeoFenceBroadcastReceiver扩展了BroadcastReceiver{

private static final String TAG = "GeoFenceBroadcastReceiv";
@Override
public void onReceive(Context context, Intent intent) {
    // TODO: This method is called when the BroadcastReceiver is receiving
    // an Intent broadcast.
    Toast.makeText(context, "Geofence triggered...", Toast.LENGTH_SHORT).show();

    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);

    if (geofencingEvent.hasError()) {
        Log.d(TAG, "onReceive: Error receiving geofence event...");
        return;
    }

    List<Geofence> geofenceList = geofencingEvent.getTriggeringGeofences();
    for (Geofence geofence: geofenceList) {
        Log.d(TAG, "onReceive: " + geofence.getRequestId());
    }

    Location location = geofencingEvent.getTriggeringLocation();
    int transitionType = geofencingEvent.getGeofenceTransition();

    switch (transitionType) {
        case Geofence.GEOFENCE_TRANSITION_ENTER:
            Toast.makeText(context, "GEOFENCE_TRANSITION_ENTER", Toast.LENGTH_SHORT).show();
            break;
        case Geofence.GEOFENCE_TRANSITION_DWELL:
            Toast.makeText(context, "GEOFENCE_TRANSITION_DWELL", Toast.LENGTH_SHORT).show();
            break;
        case Geofence.GEOFENCE_TRANSITION_EXIT:
            Toast.makeText(context, "GEOFENCE_TRANSITION_EXIT", Toast.LENGTH_SHORT).show();
            break;
    }

    throw new UnsupportedOperationException("Not yet implemented");
}
private static final String TAG=“geofenginebroadcastreceiv”;
@凌驾
公共void onReceive(上下文、意图){
//TODO:当BroadcastReceiver正在接收时调用此方法
//有意图的广播。
Toast.makeText(上下文,“地理围栏触发…”,Toast.LENGTH_SHORT.show();
GeofencingEvent GeofencingEvent=GeofencingEvent.fromIntent(intent);
if(geofencingEvent.hasError()){
Log.d(标记“onReceive:接收地理围栏事件时出错…”);
返回;
}
List geofenceList=geofencingEvent.getTriggeringGeofences();
用于(地理围栏地理围栏:地理围栏列表){
Log.d(标记“onReceive:+geopfence.getRequestId());
}
Location Location=geofencingEvent.getTriggeringLocation();
int transitionType=geofencingEvent.getGeofenceTransition();
开关(转换类型){
案例Geopfence.Geopfence\u过渡\u输入:
Toast.makeText(上下文,“地理围栏”\u TRANSITION\u ENTER),Toast.LENGTH\u SHORT.show();
打破
案例Geofence.Geofence_过渡_驻留:
Toast.makeText(上下文,“地理围栏”和“过渡”和“驻留”,Toast.LENGTH和.SHORT.show();
打破
案例Geofence.Geofence_过渡_出口:
Toast.makeText(上下文,“地理围栏”转换退出),Toast.LENGTH.SHORT.show();
打破
}
抛出新的UnsupportedOperationException(“尚未实现”);
}
}


谢谢

请编辑您的问题并提供您的日志。请注意,您正在进行的几个GeoFerning api调用可以根据文档返回空值:
fromIntent
getTriggeringGeofences
getTriggeringLocation
。我的机器不支持android emulator,当用户移动时,应用程序正在崩溃。所以,当应用程序崩溃时,我不可能提供日志。还有其他的测试方法吗?请推荐我一定要卸载应用程序(假设它是从应用商店安装的)——然后像使用模拟器一样使用studio。