Я использовал учебник Android с геофизой, который, очевидно, не работает, когда приложение закрыто. Таким образом, после поиска я заметил, что пользователь B-Ryce на SO использованного Broadcastreceiver, поэтому геоффинге запускается, даже если приложение не активно (ссылка для его вопроса). < /P>
Я просто не могу заставить геофуза к запуска, когда я выхожу за пределы /внутреннее зарегистрированное местоположение. Вот моя процедура: < /p>
/**
* GeoLocation library
*/
mGeoLocation = new GeoLocation(sInstance);
/**
* mReceiver init
*/
mReceiver = new Receiver();
sInstance.registerReceiver(mReceiver, mReceiver.createIntentFilter());
< /code>
и внутренний класс геолокации: < /p>
/*
* 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");
/**
* Return the PendingIntent
*/
return PendingIntent.getBroadcast(
mContext,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
}
< /code>
Вот как я создаю новую геофенсу: < /p>
Geofence fence = new Geofence.Builder()
.setRequestId(hashCode)
// when entering this geofence
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT)
.setCircularRegion(
Double.parseDouble(single.getSetting("latitude")),
Double.parseDouble(single.getSetting("longitude")),
Float.parseFloat(single.getSetting("radius")) // radius in meters
)
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.build();
mGeofences.add(fence);
< /code>
массив заполняется, и мы называем метод Addgeofences внутри класса геофоны < /p>
mGeoLocation.AddGeofences(mGeofences);
< /code>
android manifest.xml для приемного класса: < /p>
< /code>
и класс приемника должен просто войти в систему, когда геофенса запускает < /p>
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.d("sfen", "Broadcast recieved "+ action +" but not needed.");
}
< /code>
Проблема в том, что геофона запускается только тогда, когда я открываю карту в своем приложении, где я выбираю местоположения. Закрытие приложения (запустив его в фоновом режиме) ничего не запускает, а переходы геофоны ничего не запускают. < /P>
Может ли кто -нибудь сказать мне, что я делаю не так?>
Подробнее здесь: https://stackoverflow.com/questions/257 ... streceiver
Геоза не запускается (PendingIntents и Broadcastreceiver) ⇐ Android
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение