当前位置: 首页>>代码示例>>Java>>正文


Java ActivityRecognitionClient类代码示例

本文整理汇总了Java中com.google.android.gms.location.ActivityRecognitionClient的典型用法代码示例。如果您正苦于以下问题:Java ActivityRecognitionClient类的具体用法?Java ActivityRecognitionClient怎么用?Java ActivityRecognitionClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ActivityRecognitionClient类属于com.google.android.gms.location包,在下文中一共展示了ActivityRecognitionClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreate

import com.google.android.gms.location.ActivityRecognitionClient; //导入依赖的package包/类
@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);
}
 
开发者ID:cfagiani,项目名称:justdrive,代码行数:20,代码来源:DetectionService.java

示例2: onCreate

import com.google.android.gms.location.ActivityRecognitionClient; //导入依赖的package包/类
@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);
}
 
开发者ID:JimSeker,项目名称:googleplayAPI,代码行数:29,代码来源:MainActivity.java

示例3: onCreate

import com.google.android.gms.location.ActivityRecognitionClient; //导入依赖的package包/类
@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);
}
 
开发者ID:JimSeker,项目名称:googleplayAPI,代码行数:28,代码来源:MainActivity.java

示例4: onCreate

import com.google.android.gms.location.ActivityRecognitionClient; //导入依赖的package包/类
@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.
}
 
开发者ID:JimSeker,项目名称:googleplayAPI,代码行数:32,代码来源:MainActivity.java

示例5: startActivityUpdates

import com.google.android.gms.location.ActivityRecognitionClient; //导入依赖的package包/类
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));
}
 
开发者ID:InspectorIncognito,项目名称:androidApp,代码行数:12,代码来源:ActivityDetectionHandler.java

示例6: ActivityRecognitionManager

import com.google.android.gms.location.ActivityRecognitionClient; //导入依赖的package包/类
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);
}
 
开发者ID:cictourgune,项目名称:Pandora-sdk-android,代码行数:9,代码来源:ActivityRecognitionManager.java

示例7: onCreate

import com.google.android.gms.location.ActivityRecognitionClient; //导入依赖的package包/类
@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);
}
 
开发者ID:googlesamples,项目名称:android-play-location,代码行数:29,代码来源:MainActivity.java

示例8: ActivitySensor

import com.google.android.gms.location.ActivityRecognitionClient; //导入依赖的package包/类
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);
	}
}
 
开发者ID:simongray,项目名称:Rejsekort-Reminder,代码行数:37,代码来源:ActivitySensor.java

示例9: onInit

import com.google.android.gms.location.ActivityRecognitionClient; //导入依赖的package包/类
@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();
}
 
开发者ID:participactunibo,项目名称:MoST,代码行数:33,代码来源:PeriodicGoogleActivityRecognitionInput.java

示例10: onInit

import com.google.android.gms.location.ActivityRecognitionClient; //导入依赖的package包/类
@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();
}
 
开发者ID:participactunibo,项目名称:MoST,代码行数:33,代码来源:GoogleActivityRecognitionInput.java

示例11: startActivityRecognitionScan

import com.google.android.gms.location.ActivityRecognitionClient; //导入依赖的package包/类
/**
 * 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");
}
 
开发者ID:jpinsonault,项目名称:android_sensor_logger,代码行数:11,代码来源:LoggerService.java

示例12: ActivityRequester

import com.google.android.gms.location.ActivityRecognitionClient; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:moguai2k,项目名称:ProjektWerkstatt13,代码行数:21,代码来源:ActivityRequester.java

示例13: onCreate

import com.google.android.gms.location.ActivityRecognitionClient; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:Plonk42,项目名称:mytracks,代码行数:43,代码来源:TrackRecordingService.java

示例14: stopActivityUpdates

import com.google.android.gms.location.ActivityRecognitionClient; //导入依赖的package包/类
public void stopActivityUpdates() {
    ActivityRecognitionClient activityRecognitionClient = ActivityRecognition.getClient(context);
    activityRecognitionClient.removeActivityUpdates(pendingIntent);
    this.googleApiClient.disconnect();
    LocalBroadcastManager.getInstance(context).unregisterReceiver(broadcastReceiver);
}
 
开发者ID:InspectorIncognito,项目名称:androidApp,代码行数:7,代码来源:ActivityDetectionHandler.java

示例15: onCreate

import com.google.android.gms.location.ActivityRecognitionClient; //导入依赖的package包/类
@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);
	}
}
 
开发者ID:smo-key,项目名称:sohacks,代码行数:48,代码来源:MainActivity.java


注:本文中的com.google.android.gms.location.ActivityRecognitionClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。