7

이상한 문제가 있습니다.Android Geofencing - 의도가 없습니다?

Google 서비스를 사용하여 지오 펜싱을 구현했습니다. (아래 구현) 내 장치 (Samsung Galaxy S 및 Moto X)에서 완벽하게 작동합니다. 일부 다른 기기 (HTC Incredible S, Galaxy Note)에서는 전환 의도가 표시되지 않습니다. 못. 울타리 중간에 서있는 크고 정확한 GPS 수정. 아무것도. 로그에서 의심스러운 부분이 없습니다. 오류 없음, 경고 없음. 아니 itents 올, 서비스가 시작되지 않습니다.

그런 사람을 본 사람이 있습니까? (작동하지 않는 기기와 그렇지 않은 기기 사이의 연결이 보이지 않아 이상합니다. 제조업체가 아니며 Android 버전이 아니며 Play 서비스가 최신 버전이었습니다.)

구현 :

매니페스트 :

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="test.package" 
android:installLocation="auto" 
android:versionCode="17" 
android:versionName="1.1" > 

<uses-sdk 
    android:minSdkVersion="7" 
    android:targetSdkVersion="19" /> 

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> 
<uses-permission android:name="android.permission.VIBRATE" /> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" /> 


<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 

    <activity 
     android:name="test.package.MainActivity" 
     android:label="Compass" 
     android:screenOrientation="portrait" /> 

    <service android:name="test.package.services.geofences.ShowNotificationService" 
      android:label="@string/app_name" 
      android:exported="false"/> 

    <receiver android:name="test.package.services.geofences.UpdateGeofences"> 
     <intent-filter> 
      <action android:name="test.package.updateGeofecnes"/> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 
     </intent-filter> 
    </receiver> 

업데이트 지오 펜스 :

public class UpdateGeofences extends BroadcastReceiver implements 
     GooglePlayServicesClient.ConnectionCallbacks, 
     GooglePlayServicesClient.OnConnectionFailedListener, 
     LocationClient.OnAddGeofencesResultListener, 
     DataUpdateCallback { 

    private LocationClient mLocationClient; 
    private Context ctx; 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     Log.d("NOTICE", "Updating Geofences"); 
     ctx = context; 
     mLocationClient = new LocationClient(context, this, this); 
     mLocationClient.connect(); 
    } 

    @Override 
    public void onConnected(Bundle bundle) { 
     GeofenceProvider geofenceProvider = new GeofenceProvider(ctx); 
     geofenceProvider.open(); 

     //reactivate geofences 
     List<Geofence> geofences = geofenceProvider.getActiveGeofences(mLocationClient.getLastLocation()); 
     Intent intent = new Intent(ctx, ShowNotificationService.class); 
     PendingIntent pendingIntent = PendingIntent.getService(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 
     if (geofences.size() > 0) mLocationClient.addGeofences(geofences, pendingIntent, this); 
     else mLocationClient.disconnect(); 
    } 

    @Override 
    public void onAddGeofencesResult(int i, String[] strings) { 
     // If adding the geofences was successful 
     if (LocationStatusCodes.SUCCESS != i) { 
      Log.e("Geofences", "Error adding geofences: "+ Arrays.toString(strings)+ " Code: "+i); 
     } 
     mLocationClient.disconnect(); 
    }  
} 

보기 알림 서비스 :

그들은 기본적으로 데모 애플리케이션에서 복사하고 내가 다른 곳에서 성공적으로 사용하고 있기 때문에 나는 PlayServices에 연결하는 데 필요한 방법을 생략 UpdateGeofences에서
public class ShowNotificationService extends IntentService { 

    public ShowNotificationService() { 
     super("ReceiveTransitionsIntentService"); 
    } 

    @Override 
    protected void onHandleIntent(Intent intent) { 
     Log.d("NOTICE", "Android geofence notification!"); 
     if (LocationClient.hasError(intent)) { 
      int errorCode = LocationClient.getErrorCode(intent); 
      Log.e("ReceiveTransitionsIntentService", "Location Services error: " + Integer.toString(errorCode)); 
      Crashlytics.logException(new RuntimeException("Location Services error: "+errorCode)); 
     } else { 
      int transitionType = LocationClient.getGeofenceTransition(intent); 
      if (transitionType == Geofence.GEOFENCE_TRANSITION_ENTER) { //ak vstupujem pozriem sa ci uz sa mi to nevyhodilo dnes 
       List<Geofence> triggerList = LocationClient.getTriggeringGeofences(intent); 
       Log.d("NOTICE", "Transition Enter"); 
       GeofenceProvider mProvider = new GeofenceProvider(this); 
       mProvider.open(); 
       try { 
        for (Geofence geofence : triggerList) { 
         String id = geofence.getRequestId(); 
         String[] data = id.split(MyGeofence.delimiter); 
         Log.d("NOTICE", "Show notification: "+id); 
         if (data.length != 3) { 
          Crashlytics.logException(new RuntimeException("Invalid geofence id: " + id + "Data: "+ Arrays.toString(data))); 
          continue; 
         } 
         if (mProvider.updateLastFire(Integer.valueOf(data[2]))) { 
          NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
          builder.setContentTitle(data[0]); 
          builder.setContentText(data[1]); 
          builder.setSmallIcon(R.drawable.noticon); 
          Intent result = new Intent(this, CompassActivity.class); 
          PendingIntent pendingResult = PendingIntent.getActivity(this, 0, result, PendingIntent.FLAG_UPDATE_CURRENT); 
          builder.setContentIntent(pendingResult); 
          builder.setOngoing(false); 
          builder.setAutoCancel(true); 
          Notification not = builder.build(); 
          not.defaults = Notification.DEFAULT_ALL; 
          NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
          int notID = Integer.valueOf(data[2]); 
          mNotificationManager.notify(notID, not); 
         } 
        } 
       } catch (Exception e) { 
        Crashlytics.logException(e); 
        e.printStackTrace(); 
       } finally { 
        mProvider.close(); 
       } 

      } else if(transitionType == Geofence.GEOFENCE_TRANSITION_EXIT) { //ak odchadzam, oznacim to patricne v db 
       List<Geofence> triggerList = LocationClient.getTriggeringGeofences(intent); 
       Log.d("NOTICE", "Transition leave"); 
       GeofenceProvider mProvider = new GeofenceProvider(this); 
       mProvider.open(); 
       try { 
        for (Geofence geofence : triggerList) { 
         String id = geofence.getRequestId(); 
         String[] data = id.split(MyGeofence.delimiter); 
         if (data.length != 3) { 
          Crashlytics.logException(new RuntimeException("Invalid geofence id: " + id + "Data: "+ Arrays.toString(data))); 
          continue; 
         } 
         mProvider.invalidateLastFire(Integer.valueOf(data[2])); 
         Log.d("NOTICE", "Invalidate last fire: "+id); 
        } 
       } catch (Exception e) { 
        Crashlytics.logException(e); 
        e.printStackTrace(); 
       } finally { 
        mProvider.close(); 
       } 

      } else { // An invalid transition was reported 
       Log.e("ReceiveTransitionsIntentService", "Geofence transition error: " + Integer.toString(transitionType)); 
       Crashlytics.logException(new RuntimeException("Invalid geofence transition")); 
      } 
     } 
    } 
} 

...

주요 활동 업데이트가 시작될 때마다 UpdateGeofences를 시작하기 위해 브로드 캐스트를 보냅니다.

GeofenceProvider도 문제가되지 않습니다. 문제가없는 다른 곳에서도 같은 코드를 사용하고 있습니다.

답변

1

결국 나는 ShowNofiticationService에서 exported = "true"로 설정하여이 문제를 해결할 수있었습니다. 이처럼

는 :

<service android:name="test.package.services.geofences.ShowNotificationService" 
     android:label="@string/app_name" 
     android:exported="true"/> 

의도가 잘못된 ID로 프로세스에 의해 발사 된 것, 그리고 그 coused 보안 오류. 왜 그런 일이 일어 났는지 확신 할 수는 없지만 ...

+0

개발자는 geofence2에 넣어야 할 lat와 radius를 개발자 사이트에서 사용할 수있는 데모로 말할 수 있습니까? ? –

+1

android : exported = "true"가 어떻게 달라질 지 모릅니다. –

관련 문제