本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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.
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
}
示例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();
}
示例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();
}
示例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");
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
}