相关疑难解决方法(0)

Android Geofence最终停止获得过渡意图

我有一个以Google的地理围栏示例代码开头的应用.它可以工作几天,我得到了所有过渡意图,正如我预期的那样.然而,经过一段时间,比如3天,应用程序停止了这些意图,我不知道为什么.

当我创建我的围栏时,我将到期时间设置为Geofence.NEVER_EXPIRE

这是我的IntentService,我在它停止工作之前获得转换意图:

public class ReceiveTransitionsIntentService extends IntentService {
    @Override
    protected void onHandleIntent(Intent intent) {

        Intent broadcastIntent = new Intent();

        broadcastIntent.addCategory(GeofenceUtils.CATEGORY_LOCATION_SERVICES);

        // First check for errors
        if (LocationClient.hasError(intent)) {
                ...handle errors
        } else {

            // Get the type of transition (entry or exit)
            int transition = LocationClient.getGeofenceTransition(intent);

            // Test that a valid transition was reported
            if ((transition == Geofence.GEOFENCE_TRANSITION_ENTER)
                    || (transition == Geofence.GEOFENCE_TRANSITION_EXIT)) {

                // Post a notification
                NEVER GETS HERE
            } else {
                ...log error
            }
        }
    }
} …
Run Code Online (Sandbox Code Playgroud)

android-geofence

33
推荐指数
1
解决办法
2万
查看次数

在Google的Geofencing教程中没有看到Geofence Transitions

我正在尝试使用Google的示例测试地理围栏功能:创建和监控地理围栏.我在这里上传了代码.

问题是我从未收到进入或退出的通知.我有Wifi,4G和GPS.我试过用以下方法测试:

  1. 我甚至走出我的房子大约50英尺,然后走回来 - 但没有通知.我可以看到播放服务已连接,甚至"MainActivity.java中的GeofenceUtils.ACTION_GEOFENCES_ADDED"被触发,所以我认为Geofences正在被正确添加.
  2. 在设置中启用模拟位置并使用此假GPS应用程序并更改位置 - 从与Geofence1相同的坐标开始,然后设置为完全外部(在另一个状态) - 但我仍然没有得到退出通知.

我究竟做错了什么?ANyone成功运行了这个谷歌的例子:创建和监控地理围栏.我在这里上传了代码以便于浏览.

我只是想学习Geofencing - 检测进入和退出.我将标记任何答案作为我可以用来在我的真实设备上进行地理工作的正确答案

我输入下面的坐标和半径.

android location geofencing android-geofence

7
推荐指数
2
解决办法
6088
查看次数

地理围栏没有触发(待处理用户和广播接收者)

我已经使用了Geofences的Android教程,显然,当app关闭时,它不起作用.所以,在搜索了之后,我注意到SO上的用户b-ryce使用了BroadcastReceiver,因此即使应用程序不活动也会触发地理围栏(链接为他的SO问题).

当我移动到外部/内部注册位置时,我无法强制地理围栏触发.这是我的程序:

    /**
     * GeoLocation library
     */
    mGeoLocation = new GeoLocation(sInstance);


    /**
     * mReceiver init
     */
    mReceiver = new Receiver();
    sInstance.registerReceiver(mReceiver, mReceiver.createIntentFilter());
Run Code Online (Sandbox Code Playgroud)

在GeoLocation类中:

/*
 * Create a PendingIntent that triggers an IntentService in your
 * app when a geofence transition occurs.
 */
protected PendingIntent getTransitionPendingIntent() {
    if (mGeoPendingIntent != null) {
        return mGeoPendingIntent;
    }

    else {

        // Create an explicit Intent
        //  Intent intent = new Intent(mContext,
        //          ReceiveTransitionsIntentService.class);

        Intent intent = new Intent(getClass().getPackage().getName() + ".GEOFENCE_RECEIVE");

        /**
         * …
Run Code Online (Sandbox Code Playgroud)

android geolocation android-pendingintent android-geofence

6
推荐指数
1
解决办法
7232
查看次数