Java 类com.google.android.gms.location.ActivityRecognitionClient 实例源码

项目:justdrive    文件:DetectionService.java   
@Override
public void onCreate() {

    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
    mActivityRecognitionClient =
            new ActivityRecognitionClient(this, this, this);
    /*
     * Create the PendingIntent that Location Services uses
     * to send activity recognition updates back to this app.
     */
    Intent intent = new Intent(
            this, ActivityRecognitionIntentService.class);
    /*
     * Return a PendingIntent that starts the IntentService.
     */
    mActivityRecognitionPendingIntent =
            PendingIntent.getService(this, 0, intent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
}
项目:googleplayAPI    文件:MainActivity.java   
@SuppressWarnings("unchecked")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    mContext = this;

    // Get the UI widgets.
    mRequestActivityUpdatesButton = (Button) findViewById(R.id.request_activity_updates_button);
    mRemoveActivityUpdatesButton = (Button) findViewById(R.id.remove_activity_updates_button);
    ListView detectedActivitiesListView = (ListView) findViewById(
        R.id.detected_activities_listview);

    // Enable either the Request Updates button or the Remove Updates button depending on
    // whether activity updates have been requested.
    setButtonsEnabledState();

    ArrayList<DetectedActivity> detectedActivities = Utils.detectedActivitiesFromJson(
        PreferenceManager.getDefaultSharedPreferences(this).getString(
            Constants.KEY_DETECTED_ACTIVITIES, ""));

    // Bind the adapter to the ListView responsible for display data for detected activities.
    mAdapter = new DetectedActivitiesAdapter(this, detectedActivities);
    detectedActivitiesListView.setAdapter(mAdapter);

    mActivityRecognitionClient = new ActivityRecognitionClient(this);
}
项目:googleplayAPI    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    btn = (Button) findViewById(R.id.button);
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //do something...
            if (!gettingupdates) {
                startActivityUpdates();
            } else {
                stopActivityUpdates();
            }
        }
    });
    mContext = this;
    logger = (TextView) findViewById(R.id.logger);
    // Check to be sure that TTS exists and is okay to use
    Intent checkIntent = new Intent();
    checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    //The result will come back in onActivityResult with our REQ_TTS_STATUS_CHECK number
    startActivityForResult(checkIntent, REQ_TTS_STATUS_CHECK);

    //setup the client activity piece.
    mActivityRecognitionClient = new ActivityRecognitionClient(this);
}
项目:googleplayAPI    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    //setup fragments
    listfrag = new myListFragment();
    mapfrag = new myMapFragment();

    FragmentManager fragmentManager = getSupportFragmentManager();

    viewPager = (ViewPager) findViewById(R.id.pager);
    myFragmentPagerAdapter adapter = new myFragmentPagerAdapter(fragmentManager);
    viewPager.setAdapter(adapter);
    //viewPager.setCurrentItem(1);
    //new Tablayout from the support design library
    TabLayout mTabLayout = (TabLayout) findViewById(R.id.tablayout1);
    mTabLayout.setupWithViewPager(viewPager);

    //setup the client activity piece.
    mActivityRecognitionClient = new ActivityRecognitionClient(this);
    //setup the location pieces.
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
    mSettingsClient = LocationServices.getSettingsClient(this);
    createLocationRequest();
    createLocationCallback();
    buildLocationSettingsRequest();
    initialsetup();  //get last location and call it current spot.
}
项目:androidApp    文件:ActivityDetectionHandler.java   
public void startActivityUpdates(GoogleApiClient googleApiClient) {
    this.googleApiClient = googleApiClient;
    Intent intent = new Intent(context, DetectedActivitiesIntentService.class );
    pendingIntent = PendingIntent.getService( context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT );

    ActivityRecognitionClient activityRecognitionClient = ActivityRecognition.getClient(context);
    activityRecognitionClient.requestActivityUpdates(3000, pendingIntent);

    LocalBroadcastManager.getInstance(context).registerReceiver(broadcastReceiver,
            new IntentFilter(Constants.ACTIVITY_BROADCAST_ACTION));
}
项目:Pandora-sdk-android    文件:ActivityRecognitionManager.java   
public ActivityRecognitionManager(Context context){
    this.context = context;
    connecting = false;
       recognitionClient = new ActivityRecognitionClient(context, this, this);  

       Intent intent = new Intent(context, ActivityRecognitionIntentService.class);
       recognitionIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
项目:android-play-location    文件:MainActivity.java   
@SuppressWarnings("unchecked")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    mContext = this;

    // Get the UI widgets.
    mRequestActivityUpdatesButton = (Button) findViewById(R.id.request_activity_updates_button);
    mRemoveActivityUpdatesButton = (Button) findViewById(R.id.remove_activity_updates_button);
    ListView detectedActivitiesListView = (ListView) findViewById(
            R.id.detected_activities_listview);

    // Enable either the Request Updates button or the Remove Updates button depending on
    // whether activity updates have been requested.
    setButtonsEnabledState();

    ArrayList<DetectedActivity> detectedActivities = Utils.detectedActivitiesFromJson(
            PreferenceManager.getDefaultSharedPreferences(this).getString(
                    Constants.KEY_DETECTED_ACTIVITIES, ""));

    // Bind the adapter to the ListView responsible for display data for detected activities.
    mAdapter = new DetectedActivitiesAdapter(this, detectedActivities);
    detectedActivitiesListView.setAdapter(mAdapter);

    mActivityRecognitionClient = new ActivityRecognitionClient(this);
}
项目:Rejsekort-Reminder    文件:ActivitySensor.java   
public ActivitySensor(AbstractMode parentMode, int delay, int confidenceCutoff) {
    super(parentMode);
    Log.i("AS", "activity sensor constructor");
    mContext = parentMode.getContext();
    mInProgress = false;
    this.delay = delay;
    this.confidenceCutoff = confidenceCutoff;

    if(servicesConnected()) {

        /*
         * Instantiate a new activity recognition client. Since the
         * parent Activity implements the connection listener and
         * connection failure listener, the constructor uses "this"
         * to specify the values of those parameters.
         */
        mActivityRecognitionClient = new ActivityRecognitionClient(mContext, this, this);


        // Register the receiver of the intents sent from the IntentService.
        LocalBroadcastManager.getInstance(mContext).registerReceiver(mMessageReceiver,  new IntentFilter("ACTIVITY_RECOGNITION_DATA"));

        startUpdates();

        /*
         * Create the PendingIntent that Location Services uses
         * to send activity recognition updates back to this app.
         */
        Intent intent = new Intent(mContext, ActivitySensorIntentService.class);

        /*
         * Return a PendingIntent that starts the IntentService.
         */ 
        mActivityRecognitionPendingIntent = PendingIntent.getService(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }
}
项目:MoST    文件:PeriodicGoogleActivityRecognitionInput.java   
@Override
public void onInit() {
    checkNewState(Input.State.INITED);

    int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getContext());

    if (ConnectionResult.SUCCESS == resultCode) {
        _isLibraryAvailable = true;

        _activityRecognitionClient = new ActivityRecognitionClient(getContext(), this, this);

        _intervall = getContext().getSharedPreferences(MoSTApplication.PREF_INPUT,
                Context.MODE_PRIVATE).getLong(PREF_KEY_GOOGLE_ACTIVITY_RECOGNITION_PERIOD,
                DEFAULT_GOOGLE_ACTIVITY_RECOGNITION_PERIOD);

        _intent = new Intent();
        _intent.setAction(GOOGLE_ACTIVITY_RECOGNITION_ACTION);

        _filter = new IntentFilter();
        _filter.addAction(GOOGLE_ACTIVITY_RECOGNITION_ACTION);

        _receiver = new GoogleActivityRecognitionBroadcastReceiver();

        _pendingIntent = PendingIntent.getBroadcast(getContext(), 0, _intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

    } else {
        Log.e(TAG, "Google Play Service Library not available.");
    }

    super.onInit();
}
项目:MoST    文件:GoogleActivityRecognitionInput.java   
@Override
public void onInit() {
    checkNewState(Input.State.INITED);

    int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getContext());

    if (ConnectionResult.SUCCESS == resultCode) {
        _isLibraryAvailable = true;

        _activityRecognitionClient = new ActivityRecognitionClient(getContext(), this, this);

        _intervall = getContext().getSharedPreferences(MoSTApplication.PREF_INPUT,
                Context.MODE_PRIVATE).getLong(PREF_KEY_GOOGLE_ACTIVITY_RECOGNITION_INTERVALL,
                DEFAULT_GOOGLE_ACTIVITY_RECOGNITION_INTERVALL);

        _intent = new Intent();
        _intent.setAction(GOOGLE_ACTIVITY_RECOGNITION_ACTION);

        _filter = new IntentFilter();
        _filter.addAction(GOOGLE_ACTIVITY_RECOGNITION_ACTION);  

        _receiver = new GoogleActivityRecognitionBroadcastReceiver();

        _pendingIntent = PendingIntent.getBroadcast(getContext(), 0, _intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

    } else {
        Log.e(TAG, "Google Play Service Library not available.");
    }

    super.onInit();
}
项目:android_sensor_logger    文件:LoggerService.java   
/**
 * Call this to start a scan - don't forget to stop the scan once it's done.
 * Note the scan will not start immediately, because it needs to establish a connection with Google's servers - you'll be notified of this at onConnected
 */
public void startActivityRecognitionScan(){

    mActivityRecognitionClient  = new ActivityRecognitionClient(mContext, this, this);
    mActivityRecognitionClient.connect();
    Log.i(TAG, "startActivityRecognitionScan");
}
项目:ProjektWerkstatt13    文件:ActivityRequester.java   
/**
 * Constructor
 * 
 * @param context
 *            the application context.
 */
public ActivityRequester(Context context) {
    /* The application context. */
    this.context = context;

    /*
     * Create a new activity client, using this class to handle the
     * callbacks.
     */
    activityClient = new ActivityRecognitionClient(this.context, this, this);

    activityClient.connect();

    locBroadcastManager = LocalBroadcastManager.getInstance(context);
}
项目:mytracks    文件:TrackRecordingService.java   
@Override
public void onCreate() {
  super.onCreate();
  executorService = Executors.newSingleThreadExecutor();
  context = this;
  myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this);
  handler = new Handler();
  myTracksLocationManager = new MyTracksLocationManager(this, handler.getLooper(), true);
  activityRecognitionPendingIntent = PendingIntent.getService(context, 0,
      new Intent(context, ActivityRecognitionIntentService.class),
      PendingIntent.FLAG_UPDATE_CURRENT);
  activityRecognitionClient = new ActivityRecognitionClient(
      context, activityRecognitionCallbacks, activityRecognitionFailedListener);
  activityRecognitionClient.connect();    
  voiceExecutor = new PeriodicTaskExecutor(this, new AnnouncementPeriodicTaskFactory());
  splitExecutor = new PeriodicTaskExecutor(this, new SplitPeriodicTaskFactory());
  sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
  sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);

  // onSharedPreferenceChanged might not set recordingTrackId.
  recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;

  // Require voiceExecutor and splitExecutor to be created.
  sharedPreferenceChangeListener.onSharedPreferenceChanged(sharedPreferences, null);

  handler.post(registerLocationRunnable);

  /*
   * Try to restart the previous recording track in case the service has been
   * restarted by the system, which can sometimes happen.
   */
  Track track = myTracksProviderUtils.getTrack(recordingTrackId);
  if (track != null) {
    restartTrack(track);
  } else {
    if (isRecording()) {
      Log.w(TAG, "track is null, but recordingTrackId not -1L. " + recordingTrackId);
      updateRecordingState(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, true);
    }
    showNotification(false);
  }
}
项目:androidApp    文件:ActivityDetectionHandler.java   
public void stopActivityUpdates() {
    ActivityRecognitionClient activityRecognitionClient = ActivityRecognition.getClient(context);
    activityRecognitionClient.removeActivityUpdates(pendingIntent);
    this.googleApiClient.disconnect();
    LocalBroadcastManager.getInstance(context).unregisterReceiver(broadcastReceiver);
}
项目:sohacks    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Activity Recog
    mActivityRecognitionClient = new ActivityRecognitionClient(
            getApplicationContext(),
            (com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks) this,
            this);
    Intent intent = new Intent(getApplicationContext(),
            ActivityRecognitionIntentService.class);
    mActivityRecognitionClient.connect();
    mActivityRecognitionPendingIntent = PendingIntent.getService(
            getApplicationContext(), 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    mDrawerList.setAdapter(new ArrayAdapter<String>(this,
            R.layout.drawer_list_item, drawerNames));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
    mDrawerLayout, /* DrawerLayout object */
    R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
    R.string.drawer_open, /* "open drawer" description */
    R.string.drawer_close /* "close drawer" description */
    ) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }
    };

    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    if (savedInstanceState == null) {
        selectItem(0);
    }
}
项目:android_sensor_logger    文件:ActivityRecognitionScan.java   
/**
 * Call this to start a scan - don't forget to stop the scan once it's done.
 * Note the scan will not start immediately, because it needs to establish a connection with Google's servers - you'll be notified of this at onConnected
 */
public void startActivityRecognitionScan(){
    mActivityRecognitionClient  = new ActivityRecognitionClient(context, this, this);
    mActivityRecognitionClient.connect();
    Log.d(TAG, "startActivityRecognitionScan");
}
项目:GeoLog    文件:BackgroundService.java   
@Override
public void run() {
    Debug.log("Thread init");

    databaseHelper = Database.Helper.getInstance(context);

    alarm = (AlarmManager)context.getSystemService(ALARM_SERVICE);
    {
        Intent i = new Intent(context.getApplicationContext(), BackgroundService.class);
        i.putExtra(EXTRA_ALARM_CALLBACK, 1);
        alarmCallback = PendingIntent.getService(BackgroundService.this, 0, i, 0);
    }

    Looper.prepare();
    handler = new Handler();

    Debug.log("Registering for updates");           
    prefs = PreferenceManager.getDefaultSharedPreferences(context);                 
    long id = prefs.getLong(SettingsFragment.PREF_CURRENT_PROFILE, 0);
    if (id > 0) currentProfile = Database.Profile.getById(databaseHelper, id, null);
    if (currentProfile == null) currentProfile = Database.Profile.getOffProfile(databaseHelper);
    metric = !prefs.getString(SettingsFragment.PREF_UNITS, SettingsFragment.PREF_UNITS_DEFAULT).equals(SettingsFragment.VALUE_UNITS_IMPERIAL);
    prefs.registerOnSharedPreferenceChangeListener(preferencesUpdated);
    LocalBroadcastManager.getInstance(context).registerReceiver(databaseUpdated, new IntentFilter(Database.Helper.NOTIFY_BROADCAST));

    Debug.log("Registering for power levels");
    context.registerReceiver(batteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

    Debug.log("Connecting ActivityRecognitionClient");
    activityIntent = PendingIntent.getService(context, 1, new Intent(context, BackgroundService.class), 0);
    activityClient = new ActivityRecognitionClient(context, activityConnectionCallbacks, activityConnectionFailed);
    activityClient.connect();

    Debug.log("Connecting LocationClient");
    locationClient = new LocationClient(context, locationConnectionCallbacks, locationConnectionFailed);
    locationClient.connect();

    Debug.log("Entering loop");
    handler.post(new Runnable() {               
        @Override
        public void run() {
            updateListeners(FLAG_SETUP);
        }
    });                     
    Looper.loop();          
    Debug.log("Exiting loop");

    context.unregisterReceiver(batteryReceiver);

    LocalBroadcastManager.getInstance(context).unregisterReceiver(databaseUpdated);
    prefs.unregisterOnSharedPreferenceChangeListener(preferencesUpdated);           

    if (activityConnected) {
        activityClient.removeActivityUpdates(activityIntent);
        activityClient.disconnect();
    }
    if (locationConnected) {
        locationClient.removeLocationUpdates(locationListener);
        locationClient.disconnect();
    }           
}