@Override
 public void onConnected(Bundle arg0) {
   Log.d(TAG, "ConnectionSuccesful");
   Intent intent = new Intent(context, ActivityRecognitionService.class);
   callbackIntent =
       PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
   ActivityRecognition.ActivityRecognitionApi.requestActivityUpdates(
       mActivityRecognitionClient, 20, callbackIntent);
 }
 public void stopActivityRecognitionScan() {
   try {
     ActivityRecognition.ActivityRecognitionApi.removeActivityUpdates(
         mActivityRecognitionClient, callbackIntent);
     mActivityRecognitionClient.disconnect();
     Log.d(TAG, "stopActivityRecognitionScan");
   } catch (IllegalStateException e) {
   }
 }