首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当用户进入Geofence或居住在Geofence时,应用程序意外关闭。

当用户进入Geofence或居住在Geofence时,应用程序意外关闭。
EN

Stack Overflow用户
提问于 2020-11-22 07:52:21
回答 1查看 91关注 0票数 1

我已经在我的android应用程序中实现了Geofence服务,以便在用户进入、居住或退出该Geofence时通知用户。在我的实现中,我可以通过对特定位置进行长时间的按压,在任何地方添加地理信息。但是当用户进入那个Geofence或者Geofence是添加这样的用户已经在Geofence,应用程序意外崩溃。

我怎样才能解决这个问题?

这是我的GeofenceBroadcastReceiver.java课。

代码语言:javascript
复制
public class GeoFenceBroadcastReceiver extends 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");
    }
}

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2022-09-27 14:32:10

在某些情况下,geofencingEvent返回null,因此可以实现相应的对策。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64951781

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档