Java GeofencingApi addGeofences未收到通知
我已经为地理围栏创建了注册类,并创建了一个主要活动来使用它。我使用了此页面上的代码:[ 这是我的主要活动:Java GeofencingApi addGeofences未收到通知,java,android,google-api-client,android-geofence,Java,Android,Google Api Client,Android Geofence,我已经为地理围栏创建了注册类,并创建了一个主要活动来使用它。我使用了此页面上的代码:[ 这是我的主要活动: import android.content.Intent; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.util.Log; import com.google.android.gms.common.ConnectionResult; import com
import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.util.Log;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.location.Geofence;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import java.util.ArrayList;
import java.util.List;
public class MapsActivity extends FragmentActivity implements GeofencingRegistererCallbacks{
private static final String TAG= "GeoFencingTEst-MainActivity";
private GoogleMap mMap; // Might be null if Google Play services APK is not available.
private GeofencingRegisterer gRegister;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setUpMapIfNeeded();
gRegister= new GeofencingRegisterer(this);
gRegister.setGeofencingCallback(this);
List<Geofence> geofenceList= new ArrayList<Geofence>();
Geofence geofence=new Geofence.Builder()
.setRequestId("1")
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)
.setCircularRegion(37.0, -122.0, 10)
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.build();
geofenceList.add(geofence);
gRegister.registerGeofences(geofenceList);
//startService(new Intent(this, GeofencingReceiver.class));
Log.e(TAG, ""+gRegister.getRequestPendingIntent());
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
/**
* Sets up the map if it is possible to do so (i.e., the Google Play services APK is correctly
* installed) and the map has not already been instantiated.. This will ensure that we only ever
* call {@link #setUpMap()} once when {@link #mMap} is not null.
* <p/>
* If it isn't installed {@link SupportMapFragment} (and
* {@link com.google.android.gms.maps.MapView MapView}) will show a prompt for the user to
* install/update the Google Play services APK on their device.
* <p/>
* A user can return to this FragmentActivity after following the prompt and correctly
* installing/updating/enabling the Google Play services. Since the FragmentActivity may not
* have been completely destroyed during this process (it is likely that it would only be
* stopped or paused), {@link #onCreate(Bundle)} may not be called again so we should call this
* method in {@link #onResume()} to guarantee that it will be called.
*/
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
/**
* This is where we can add markers or lines, add listeners or move the camera. In this case, we
* just add a marker near Africa.
* <p/>
* This should only be called once and when we are sure that {@link #mMap} is not null.
*/
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
@Override
public void onApiClientConnected() {
Log.e(TAG,"onApiClientConnected");
}
@Override
public void onApiClientSuspended() {
Log.e(TAG,"onApiClientSuspended");
}
@Override
public void onApiClientConnectionFailed(ConnectionResult connectionResult) {
Log.e(TAG,"onApiClientConnectionFailed");
}
@Override
public void onGeofencesRegisteredSuccessful() {
Log.e(TAG,"onGeofencesRegisteredSuccessful"+gRegister.getRequestPendingIntent());
}
我认为问题在于服务器没有在后台运行,因为这是日志:
01-10 10:57:56.406: I/CheckinRequestBuilder(1708): Classify the device as Phone.
01-10 10:57:59.727: I/ConfigFetchService(1708): fetch service done; releasing wakelock
01-10 10:57:59.729: I/ActivityManager(1224): Waited long enough for: ServiceRecord{14d38e65 u0 com.google.android.gms/.wearable.service.WearableService}
01-10 10:57:59.730: I/ConfigFetchService(1708): stopping self
01-10 10:57:59.733: I/ConfigService(1656): onDestroy
有人有解决方案或EXPAMP代码可供使用吗?您有服务来处理进入地理围栏引发的意图吗 试试下面这个
01-10 10:57:56.406: I/CheckinRequestBuilder(1708): Classify the device as Phone.
01-10 10:57:59.727: I/ConfigFetchService(1708): fetch service done; releasing wakelock
01-10 10:57:59.729: I/ActivityManager(1224): Waited long enough for: ServiceRecord{14d38e65 u0 com.google.android.gms/.wearable.service.WearableService}
01-10 10:57:59.730: I/ConfigFetchService(1708): stopping self
01-10 10:57:59.733: I/ConfigService(1656): onDestroy