1

내 지오 펜스가 잘 작동, 그렇지 않으면 다른 모든 것들 작동을 멈 춥니 변경되었습니다. 여기 내 지오 펜스를 다시 등록하려고하는 방송 수신기의 코드입니다.공급자에서 Android 지오 펜스를 변경하는 방법이 변경 되었습니까? 공급자에

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

public class LocationProviderChangedReceiver extends BroadcastReceiver implements GoogleApiClient.ConnectionCallbacks,GoogleApiClient.OnConnectionFailedListener,ResultCallback<Status> { 
    int i=0; 
    protected GoogleApiClient mGoogleApiClient; 
    Geofence geofence; 
    Context context; 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     i=i++; 
     this.context=context; 
     Toast.makeText(context,"Provider changed ,Geofencing restarted.",Toast.LENGTH_LONG).show(); 
     Log.wtf("senpai","oooooo"+i); 
     LatLng latLng=new LatLng(28.5795613,77.3136267); 

     geofence=new Geofence.Builder() 
       .setRequestId("x").setCircularRegion(latLng.latitude,latLng.longitude, Constants.GEOFENCE_RADIUS_IN_METERS) 
       .setExpirationDuration(Constants.GEOFENCE_EXPIRATION_IN_MILLISECONDS) 
       .setLoiteringDelay(500) 
       .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT|Geofence.GEOFENCE_TRANSITION_DWELL) 
       .build(); 

     mGoogleApiClient = new GoogleApiClient.Builder(context) 
       .addConnectionCallbacks(this) 
       .addOnConnectionFailedListener(this) 
       .addApi(LocationServices.API) 
       .build(); 

    } 

    @Override 
    public void onConnected(@Nullable Bundle bundle) { 
     try { 
      LocationServices.GeofencingApi.removeGeofences(mGoogleApiClient, getGeofencePendingIntent()).setResultCallback(this); // Result processed in onResult(). 
      LocationServices.GeofencingApi.addGeofences(mGoogleApiClient, getGeofencingRequest(), getGeofencePendingIntent()).setResultCallback(this); // Result processed in onResult(). 
     } catch (SecurityException securityException) { 
      // Catch exception generated if the app does not use ACCESS_FINE_LOCATION permission. 
     } 
    } 

    @Override 
    public void onConnectionSuspended(int i) { 

    } 

    @Override 
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { 

    } 

    @Override 
    public void onResult(@NonNull Status status) { 

    } 

    private PendingIntent getGeofencePendingIntent() { 
     Intent intent = new Intent("ACTION_RECEIVE_GEOFENCE"); 
     // We use FLAG_UPDATE_CURRENT so that we get the same pending intent back when calling addgeoFences() 
     return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 
    } 

    private GeofencingRequest getGeofencingRequest() { 
     GeofencingRequest.Builder builder = new GeofencingRequest.Builder(); 
     builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER); 
     builder.addGeofence(geofence); 
     return builder.build(); 
    } 
} 

내 활동에서 나는 똑같이했습니다. 지오 펜싱을 다시 시작하려면 어떻게해야합니까? 나의 Geofencer 예를

다음

일부 조각입니다 작동 :

답변

0

실행 지리적 울타리를 유지하려면, 당신은 (a)는 위치 제공 업체 변경에 다시 등록 지리적 울타리도 (b)는 장치 다시 부팅해야 구글은 지오 펜싱 플레이 테스트하는 다른 라이브러리와 비교 : 다시로 (

<!-- Listen for the device starting up for re-registration tasks --> 
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 
... 
    <receiver 
     android:name=".geo.GeoRestartReceiver" 
     android:enabled="true" 
     android:exported="true"> 
     <intent-filter> 
      <category android:name="android.intent.category.DEFAULT" /> 

      <action android:name="android.intent.action.BOOT_COMPLETED" /> <!-- android.intent.action.LOCKED_BOOT_COMPLETED would be triggered earlier, in case we don't need access to credential secure storage --> 
      <action android:name="android.intent.action.QUICKBOOT_POWERON" /> 
      <action android:name="com.htc.intent.action.QUICKBOOT_POWERON" /> 
      <action android:name="android.location.PROVIDERS_CHANGED" /> 
     </intent-filter> 
    </receiver> 

은 (재)하는 수신기를 작성하여 지오 펜싱을 시작합니다

모두 이벤트에 대한 매니페스트에 방송 수신기를 등록 지오 펜스 요청 만들기 :

public class GeoRestartReceiver extends BroadcastReceiver { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     if (!GeoLocationUtil.isGpsEnabled(context) || !GeoLocationUtil.hasGpsPermissions(context)) 
      return; 

     GeofenceSettings settings = new GeofenceSettings(context); 
     if (!settings.isGeofencingActive()) { 
      return; 
     } 

     GeofenceProvider geofenceProvider = new PlayGeofenceProvider(context); 
     geofenceProvider.start(homeLocation, enterRadius, exitRadius, 
      initTrigger, usePolling); 
    } 
} 

대부분의 Google Geofencing API 논리는 사용자 정의 클래스 내에 캡슐화되어 있습니다. Geofencer 레포에서 자세한 내용을 확인하십시오.