Created
December 24, 2015 17:09
-
-
Save anubhaw2091/64f394e47032cb280da9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void onCreate(Bundle savedInstanceState) { | |
System.out.println("Anubhaw-oncreate"); | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
// Get the UI widgets. | |
mAddGeofencesButton = (Button) findViewById(R.id.add_geofences_button); | |
mRemoveGeofencesButton = (Button) findViewById(R.id.remove_geofences_button); | |
// Empty list for storing geofences. | |
mGeofenceList = new ArrayList<Geofence>(); | |
// Initially set the PendingIntent used in addGeofences() and removeGeofences() to null. | |
mGeofencePendingIntent = null; | |
// Retrieve an instance of the SharedPreferences object. | |
mSharedPreferences = getSharedPreferences(Constants.SHARED_PREFERENCES_NAME, | |
MODE_PRIVATE); | |
// Get the value of mGeofencesAdded from SharedPreferences. Set to false as a default. | |
mGeofencesAdded = mSharedPreferences.getBoolean(Constants.GEOFENCES_ADDED_KEY, false); | |
setButtonsEnabledState(); | |
// Get the geofences used. Geofence data is hard coded in this sample. | |
populateGeofenceList(); | |
// Kick off the request to build GoogleApiClient. | |
buildGoogleApiClient(); | |
//mAddGeofencesButton.performClick(); -- this says that am not connected. | |
if(mGoogleApiClient.isConnected()==true) | |
{ System.out.println("yeah.."); | |
addGeofencesButtonHandler(null); --this too says am not connected. | |
} | |
} | |
----------------------- | |
public void addGeofencesButtonHandler(View view) { | |
System.out.println("Anubhaw-addgeo"); | |
if (!mGoogleApiClient.isConnected()) { | |
Toast.makeText(this, getString(R.string.not_connected), Toast.LENGTH_SHORT).show(); | |
return; | |
} | |
try { | |
LocationServices.GeofencingApi.addGeofences( | |
mGoogleApiClient, | |
// The GeofenceRequest object. | |
getGeofencingRequest(), | |
// A pending intent that that is reused when calling removeGeofences(). This | |
// pending intent is used to generate an intent when a matched geofence | |
// transition is observed. | |
getGeofencePendingIntent() | |
).setResultCallback(this); // Result processed in onResult(). | |
} catch (SecurityException securityException) { | |
// Catch exception generated if the app does not use ACCESS_FINE_LOCATION permission. | |
logSecurityException(securityException); | |
} | |
} | |
public void abc() | |
{ | |
mGoogleApiClient.connect(); | |
if (!mGoogleApiClient.isConnected()) { | |
Toast.makeText(this, getString(R.string.not_connected), Toast.LENGTH_SHORT).show(); | |
return; | |
} | |
try { | |
LocationServices.GeofencingApi.addGeofences( | |
mGoogleApiClient, | |
// The GeofenceRequest object. | |
getGeofencingRequest(), | |
// A pending intent that that is reused when calling removeGeofences(). This | |
// pending intent is used to generate an intent when a matched geofence | |
// transition is observed. | |
getGeofencePendingIntent() | |
).setResultCallback(this); // Result processed in onResult(). | |
} catch (SecurityException securityException) { | |
// Catch exception generated if the app does not use ACCESS_FINE_LOCATION permission. | |
logSecurityException(securityException); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment