Hi All,
I am trying to create a simple geofence and trying to sysout when I am entrying or exiting the geo fence. I have tried a simple positive scenario and using the geofencing mock app from android developer site but I am not getting any responses.
My main activity looks like this..
public class MainActivity extends ActionBarActivity implements
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener, LocationListener,
com.google.android.gms.location.LocationListener,
LocationClient.OnAddGeofencesResultListener {
private LocationClient locationClient;
private ArrayList<Geofence> geoFenceList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
geoFenceList = new ArrayList<Geofence>();
locationClient = new LocationClient(this, this, this);
locationClient.connect();
}
@Override
public void onConnected(Bundle connectionHint) {
Geofence geofence = new Geofence.Builder().setRequestId("1")
.setCircularRegion(29.569332, 98.591356, 100)
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER).build();
geoFenceList.add(geofence);
locationClient.addGeofences(geoFenceList, createPendingIntent(), this);
Toast.makeText(this, "Location client connected", Toast.LENGTH_SHORT).show();
}
private PendingIntent createPendingIntent() {
Intent intent = new Intent(this,
ReceiveGeofenceTransitionIntentService.class);
return PendingIntent.getService(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
@Override
public void onAddGeofencesResult(int statusCode, String[] geofenceRequestIds) {
}
@Override
public void onLocationChanged(Location arg0) {
}
@Override
public void onProviderDisabled(String arg0) {
}
@Override
public void onProviderEnabled(String arg0) {
}
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
}
@Override
public void onConnectionFailed(ConnectionResult result) {}
@Override
public void onDisconnected() {
}
}
Intent service class ....
public class ReceiveGeofenceTransitionIntentService extends IntentService {
public ReceiveGeofenceTransitionIntentService() {
super("ReceiveGeofenceTransitionsIntentService");
}
@Override
protected void onHandleIntent(Intent intent) {
Intent broadcastIntent = new Intent();
broadcastIntent.addCategory(GeofenceUtils.CATEGORY_LOCATION_SERVICES);
int transition = LocationClient.getGeofenceTransition(intent);
if ((transition == Geofence.GEOFENCE_TRANSITION_ENTER) ||
(transition == Geofence.GEOFENCE_TRANSITION_EXIT))
System.out.println("Geofence Transition occured!!!!!!!!!!");
Toast.makeText(this, "Geofence Transition occured", Toast.LENGTH_SHORT).show();
{
}
}
}
I am not able to understand where I am going wrong. I am giving two locations in the mock geofence app one is around which I am building the geofence and other pretty far away.I could see the transition of my device in google to and fro between those two locations but I am not getting any transition notification from my application.
My manifest goes like this....
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ocrvin"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"
/>
<service
android:name="com.aol.android.geofence.ReceiveTransitionsIntentService"
android:exported="false" >
</service>
<intent-filter >
<action android:name="com.aol.android.geofence.ACTION_RECEIVE_GEOFENCE"/>
</intent-filter>
</receiver>
<activity
android:name="com.prototype.ocrvin.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>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
</manifest>
Please help me as I am stuck in this for many days.