google oyun hizmetlerinden geofencing api'yi kullanmaya çalışıyorum ancak yayın alıcımın onReceive()
yöntemini tetiklemesini sağlayamıyorum.Android geofencing API BroadcastReceiver tetiklenmedi
Çalıştırmak için gereken her şeye saygı duyuyorum ama geçiş olayı almıyorum.
- Ben
- Ben
- ben kayıt
ACCESS_FINE_LOCATION
izni talep benim bağımlılıkları google oyun hizmetleri benim set ihraç değeri ileBroadcastReceiver
"true" (bazı gerektiğinde söylemek) benim Manifest içinde - Ben geçiş türleri ve ben geofence ortasında kesin sahte konuma sahip çalıştı
- hiçbir sona erme hem (benim cep telefonumdan Google Maps ile doğrulanmış) değilim tam olarak konumu büyük geofence eklemek ve başka bir jeopanın dışında nce 10 saniye sonra benim cep telefonunuzun kullanım yeri ben olan ve olmayan çalıştı internet bağlantısı
- doğrulanmadı
- oldu ve mod yüksek doğrulukta kuruldu doğruladıktan
- (ve
ACCESS_MOCK_LOCATION
persmission mevcuttu emin yapılan) geofence
ama yine de başarılı bir onAddGeofencesResult()
geri arama olsun, ama hiçbir onReceive()
geri arama ekledikten sonra LocationClient ayırmadan. Bir Nexus 5 ve Nexus 7 ile denedim ve her ikisi de geofence geçişlerini tetikleyemedi.
Örneğini de https://developer.android.com/training/location/geofencing.html üzerinde denedim, ancak davranışı aynıydı. Ben (değil o yapıda) Aşağıdaki satırları
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<receiver android:name="novom.anyware.anywaresdk.GeofencesReceiver" android:exported="true" />
<meta-data android:name="com.google.android.gms.version" android:value="4323000" />
Ve build.gradle dosyasında
, ben dahil benim Manifest olarakpublic class GeofencesReceiver extends BroadcastReceiver implements ConnectionCallbacks, OnConnectionFailedListener, OnAddGeofencesResultListener {
private final static String TAG = "GeofencesReceiver";
private Context context = null;
private LocationClient locationClient = null;
/**
* An empty constructor is needed by the manifest.
*/
@SuppressWarnings("unused")
public GeofencesReceiver(){}
public GeofencesReceiver(Context context){
this.context = context;
locationClient = new LocationClient(context, this, this);
locationClient.connect();
}
@Override
public void onConnected(Bundle bundle) {
new Thread(new Runnable() {
@Override
public void run() {
List<Geofence> geofences = getGeofences();
if(geofences.size() > 0){
Intent geofenceBroadcastReceiverIntent = new Intent(context, GeofencesReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, geofenceBroadcastReceiverIntent, PendingIntent.FLAG_UPDATE_CURRENT);
locationClient.addGeofences(geofences, pi, GeofencesReceiver.this);
}else
Log.w(TAG, "No GPS zone found");
}
}).start();
}
private List<Geofence> getGeofences(){
Vector<Geofence> geofences = new Vector<Geofence>();
Geofence geofence = new Geofence.Builder()
.setRequestId("1")
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT)
.setCircularRegion(45.2676018, -72.1572185, 100)
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.build();
geofences.add(geofence);
return geofences;
}
@Override
public void onDisconnected() {
Log.d(TAG, "onDisconnected");
}
@Override
public void onAddGeofencesResult(int i, String[] strings) {
if(i != LocationStatusCodes.SUCCESS)
Log.e(TAG, "Failed to add geofences");
else
Log.d(TAG, "Geofences successfully added");
locationClient.disconnect();
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.e(TAG, "onConnectionFailed");
}
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "onReceive");
if(LocationClient.hasError(intent)){
int errorCode = LocationClient.getErrorCode(intent);
Log.e(TAG, "Location Services error: " + Integer.toString(errorCode));
return;
}
int transitionType = LocationClient.getGeofenceTransition(intent);
if(transitionType == Geofence.GEOFENCE_TRANSITION_ENTER || transitionType == Geofence.GEOFENCE_TRANSITION_EXIT) {
List<Geofence> triggerList = LocationClient.getTriggeringGeofences(intent);
for(Geofence geofence : triggerList){
Log.d(TAG, (transitionType == Geofence.GEOFENCE_TRANSITION_ENTER ? "Entering" : "Exiting") + " GPS zone " + geofence.getRequestId());
}
}else{
Log.e(TAG, "Geofence transition error: " + transitionType);
}
}
}
: Burada
benimBroadcastReceiver
sınıftır gibi hizmetler
dependencies {
compile 'com.google.android.gms:play-services:4.3.23'
}
Bütün gününü neden kullanmadığını anlamaya çalıştım ' t çalış ... Logcat'tan bu satırları buldum, ancak sorunla ilgili olup olmadıklarından emin değilim, çünkü Google'da Geofencing ile ilgili bu tür hatalarla ilgili bir yazı bulamıyorum. kimse bana yardımcı olabilir, ben ben GPS_PROVIDER kayıtlı LocationManager ile kendi Google'ın bize algoritmayı uygulamak için gidiyorum ve bu benim kullanıcıların pil tüketimini gidiyor korku
04-07 09:01:14.631 1160-1319/? I/GCoreUlr﹕ Successfully inserted location
04-07 09:01:14.631 1160-1319/? I/GCoreUlr﹕ Not calling LocationReportingService, hasMoved: true, elapsed millis: 580166, request: Phone
04-07 09:02:16.481 1160-1319/? I/GCoreUlr﹕ Successfully inserted location
04-07 09:02:16.501 1160-1319/? I/GCoreUlr﹕ Starting service, intent=Intent { cmp=com.google.android.gms/com.google.android.location.reporting.LocationReportingService }, extras=null
04-07 09:02:16.571 1210-1252/? W/GLSUser﹕ GoogleAccountDataService.getToken()
04-07 09:02:16.601 1160-3780/? I/qtaguid﹕ Failed write_ctrl(u 69) res=-1 errno=22
04-07 09:02:16.601 1160-3780/? I/qtaguid﹕ Untagging socket 69 failed errno=-22
04-07 09:02:16.601 1160-3780/? W/NetworkManagementSocketTagger﹕ untagSocket(69) failed with errno -22
04-07 09:02:16.601 1160-3780/? I/imp﹕ I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond
04-07 09:02:16.601 1160-3780/? I/imp﹕ Retrying request
04-07 09:02:17.501 1160-6156/? I/GCoreUlr﹕ Starting service, intent=Intent { act=com.google.android.location.reporting.ACTION_UPDATE_ACTIVE_STATE cmp=com.google.android.gms/com.google.android.location.reporting.service.DispatchingService }, extras=null
04-07 09:02:17.511 1160-6156/? I/GCoreUlr﹕ Batch Location Update succeeded for account account#7#
04-07 09:02:17.571 1160-1319/? I/GCoreUlr﹕ Ensuring that reporting is active for [account#7#]
...
gps konumlarını taklit ediyor musunuz? geofence hassasiyeti güvenilir olmadığını da söyleyebilirim –
Ben de sahte yerlerde denedim.Geofence'nin ortasında küçük bir doğrulukla bir yer kullandım. Gerçek konumumu kullandığımda aynen öyle yaptı. –
olay yalnızca geofence –