Advertisement
Guest User

Untitled

a guest
May 5th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. /**
  2. * Runs when a GoogleApiClient object successfully connects.
  3. */
  4. @Override
  5. public void onConnected(Bundle connectionHint) {
  6.  
  7. Intent mIntent = new Intent(context, LocationReceiver.class);
  8. PendingIntent mPendingIntent = PendingIntent.getBroadcast(context, 42, mIntent, PendingIntent.FLAG_CANCEL_CURRENT);
  9.  
  10. LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, mPendingIntent);
  11. }
  12.  
  13. <receiver
  14. android:name=".LocationReceiver"
  15. android:enabled="true"
  16. android:exported="true" >
  17. <intent-filter>
  18. <action android:name="com.myapp.databerries.LOCATION_READY" />
  19. <category android:name="android.intent.category.DEFAULT" />
  20. </intent-filter>
  21. </receiver>
  22.  
  23. public class LocationReceiver extends BroadcastReceiver {
  24. public LocationReceiver() {
  25. }
  26.  
  27. @Override
  28. public void onReceive(Context context, Intent intent) {
  29.  
  30. Bundle b = intent.getExtras();
  31. Location loc = (Location)b.get(android.location.LocationManager.KEY_LOCATION_CHANGED);
  32. if (loc != null)
  33. Log.d("hello", "location = " + loc.toString());
  34. else
  35. Log.d("hello", "location = null");
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement