지오 펜싱 앱을 만들려고 시도 중이지만 기본 활동이 시작될 때 지오 펜스를 등록하는 것처럼 보입니다. 앱이 닫힐 때 인 텐트 서비스가 수신을 중지합니다. 그래서, 지오 펜스 로직을 인 텐트 서비스 (인 텐트 처리 코드와 함께)로 옮기고 서비스가 시작되었는지 확인하지만 이제는 서비스가 어떤 의도를 전혀받지 못한다!Android 앱이 지오 펜스를 추가하고 동일한 서비스에서 인 텐트를 수신합니다.
(구글 API 클라이언트가 내장 연결) 서비스의 모든 등 기본적으로, 나는이 '의도 핸들러와 지오 펜스 등록 물건 onConnected
레지스터 지오 펜스, 모두, onCreate
에서 이루어집니다
public class GeofenceTransitionsIntentService extends IntentService implements ConnectionCallbacks, OnConnectionFailedListener, ResultCallback<Status>
서비스 정의 이러한 의도를 처리하기 위해 의도 된 동일한 서비스에서 심하게 차용 한 지오 펜싱 샘플 코드 (문서)를 구현하려고 시도했습니다.
모든 주요 활동은 서비스를 시작하고 서비스에서 수신 된 지오 펜스 알림과 관련된 것들을 그립니다.
자세한 정보가 필요하면 알려주세요.
편집 우리가 더 많은 정보가 필요 것 같다 있도록
확인 - 서비스의 개요 :
public class GeofenceTransitionsIntentService extends IntentService implements ConnectionCallbacks, OnConnectionFailedListener, ResultCallback<Status> {
protected static final String TAG = "GeofenceTransitionsIS";
protected GoogleApiClient mGoogleApiClient;
protected ArrayList<Geofence> mGeofenceList;
private boolean mGeofencesAdded;
private PendingIntent mGeofencePendingIntent;
private SharedPreferences mSharedPreferences;
public GeofenceTransitionsIntentService() {
super(TAG);
}
@Override
public void onCreate() {
super.onCreate();
buildGoogleApiClient();
populateGeofenceList();
mGoogleApiClient.connect();
}
...
@Override
protected void onHandleIntent(Intent intent) {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
// handle the intent, send a notification
}
private void sendNotification(String notificationDetails) {
// sends a notification
}
@Override
public void onConnected(Bundle connectionHint)
{
LocationServices.GeofencingApi.addGeofences(
mGoogleApiClient,
getGeofencingRequest(),
getGeofencePendingIntent()
).setResultCallback(this);
}
// straight out of the example
private GeofencingRequest getGeofencingRequest()
{
...
}
// from a branch of the example that reuses the pending intent
private PendingIntent getGeofencePendingIntent()
{
if (mGeofencePendingIntent != null)
{
return mGeofencePendingIntent;
}
Intent intent = new Intent(this, GeofenceTransitionsIntentService.class);
mGeofencePendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
return mGeofencePendingIntent;
}
public void populateGeofenceList() {
for (thing place : listofplaces) {
mGeofenceList.add(...)
}
}
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
public void onResult(Status status)
{
// were fences added? usually yes
}
}
내 연구 실망했다 - 나는 사람들이 할 수있는 주장 참조 브로드 캐스트 리시버 (첫 번째 주석 참조)에서 이런 일을하고 서비스에서는하지 않습니까?
는 내가 통해 일하고 한 모든 버전에서 꽤 난도질 manifest.xml 있습니다<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<service android:name=".GeofenceTransitionsIntentService"
android:exported="true"
android:enabled="true">
<intent-filter >
<action android:name="com.aol.android.geofence.ACTION_RECEIVE_GEOFENCE"/>
</intent-filter>
</service>
...
</application>
어느 쪽도 아니 intent-filter
도 전혀 도움 서비스 정의에 android:exported="true"
를 추가.
난 안드로이드 개발자가 아니야 * – opticaliqlusion
아마도이 질문은 당신을 도울 수 있습니다. http://stackoverflow.com/questions/21090674/android-geofencing-no-coming-intents?rq=1 – TychoTheTaco
@TychoTheTaco는 응답 해 주셔서 감사하지만 효과가있는 것 같지 않습니다 - "내 보낸"추가, 다시 작성 및 다시 시작됨 앱 + 서비스, 아직 아무것도. 디버깅 결과가 더 효과적이지 않을 수도 있습니다. – opticaliqlusion