本文整理汇总了Java中com.google.android.gms.location.ActivityRecognitionClient.connect方法的典型用法代码示例。如果您正苦于以下问题:Java ActivityRecognitionClient.connect方法的具体用法?Java ActivityRecognitionClient.connect怎么用?Java ActivityRecognitionClient.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.location.ActivityRecognitionClient
的用法示例。
在下文中一共展示了ActivityRecognitionClient.connect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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");
}
示例2: 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);
}
示例3: 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);
}
}
示例4: 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);
}
}
示例5: 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(context, this, this);
mActivityRecognitionClient.connect();
Log.d(TAG, "startActivityRecognitionScan");
}
示例6: run
import com.google.android.gms.location.ActivityRecognitionClient; //导入方法依赖的package包/类
@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();
}
}