地理围栏注册成功,但地理围栏没有调用onHandleIntent

时间:2018-05-15 09:56:11

标签: java android google-play-services android-geofence

我以这种方式注册地理围栏:

GeofencingClient client = LocationServices.getGeofencingClient(context);
GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
            builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);
            builder.addGeofence(new Geofence.Builder()
                    .setRequestId(buildRequestId(objectId))
                    .setCircularRegion(location.getLatitude(), location.getLongitude(), 500)
                    .setExpirationDuration(Geofence.NEVER_EXPIRE)
                    .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT)
                    .build());
            client.addGeofences(builder.build(), PendingIntent.getService(context, objectId,
                    new Intent(context, HomeGeofenceService.class).putExtra(KEY_OBJECT_ID, objectId), PendingIntent.FLAG_UPDATE_CURRENT)).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    ObjectManager.getInstance(objectId).setLocationNotifEnabled(false);
                    ObjectManager.save();
                    int statusCode = -1;
                    if (e instanceof ApiException)
                        statusCode = ((ApiException) e).getStatusCode();
                    context.sendBroadcast(new Intent(UiConstants.ACTION_GEOFENCE_ERROR).putExtra(KEY_CODE, statusCode));
                }
            });

清单中的服务:

<service android:name=".services.HomeGeofenceService"/>
play services version: implementation 'com.google.android.gms:play-services-location:15.0.1'

服务

public class HomeGeofenceService extends IntentService {
public HomeGeofenceService() {
        super(HomeGeofenceService.class.getSimpleName());
    }
protected void onHandleIntent(Intent intent) { /***some code**/ }
}

权限列表:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.USE_FINGERPRINT"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>

targetSdkVersion 27

此代码从4月19日起在我们的应用程序中正常运行。这个问题可以与我们在俄罗斯地区的事实联系起来吗?随着所有IP禁令。或者也许还有其他一些问题?

0 个答案:

没有答案