本文整理汇总了Java中com.google.android.gms.location.FusedLocationProviderApi类的典型用法代码示例。如果您正苦于以下问题:Java FusedLocationProviderApi类的具体用法?Java FusedLocationProviderApi怎么用?Java FusedLocationProviderApi使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FusedLocationProviderApi类属于com.google.android.gms.location包,在下文中一共展示了FusedLocationProviderApi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: requestLocation
import com.google.android.gms.location.FusedLocationProviderApi; //导入依赖的package包/类
/**
* Tests for requestLocation.
*
* @throws Exception
*/
@Test
public void requestLocation() throws Exception {
GoogleApiClient mockGoogleApiClient = mock(GoogleApiClient.class);
doReturn(true).when(mockGoogleApiClient).isConnected();
LocationManager mockLocationManager = spy(mLocationManager);
Whitebox.setInternalState(mockLocationManager, "googleApiClient", mockGoogleApiClient);
FusedLocationProviderApi mockLocationProviderApi = mock(FusedLocationProviderApi.class);
Whitebox.setInternalState(LocationServices.class, "FusedLocationApi", mockLocationProviderApi);
// Testing when a customer did not disableLocationCollection.
Whitebox.invokeMethod(mockLocationManager, "requestLocation");
verify(mockLocationProviderApi).requestLocationUpdates(any(GoogleApiClient.class),
any(LocationRequest.class), any(LocationListener.class));
// Testing when a customer disableLocationCollection.
Leanplum.disableLocationCollection();
Whitebox.invokeMethod(mockLocationManager, "requestLocation");
verifyNoMoreInteractions(mockLocationProviderApi);
}
示例2: onReceive
import com.google.android.gms.location.FusedLocationProviderApi; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
this.context=context;
notificationManager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
nBuilder = new NotificationCompat.Builder(context);
nBuilder.setContentTitle("DroidAssistant");
nBuilder.setTicker("DroidAssistant");
nBuilder.setSmallIcon(R.drawable.robert_icono);
nBuilder.setLargeIcon(BitmapFactory.decodeResource(Resources.getSystem(), R.drawable.robert_icono));
nBuilder.setAutoCancel(true);
mLastLocation = intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED);
if(mLastLocation==null) {
}
else {
endLatitude=mLastLocation.getLatitude();
endLongitude=mLastLocation.getLongitude();
fetchLocationDB();
}
}
示例3: locationUpdated
import com.google.android.gms.location.FusedLocationProviderApi; //导入依赖的package包/类
/**
* Called when the location has been updated
*/
private void locationUpdated(Intent intent) {
Log.v(TAG, ACTION_LOCATION_UPDATED);
// Extra new location
Location location =
intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED);
if (location != null) {
LatLng latLngLocation = new LatLng(location.getLatitude(), location.getLongitude());
// Store in a local preference as well
Utils.storeLocation(this, latLngLocation);
// Send a local broadcast so if an Activity is open it can respond
// to the updated location
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}
}
示例4: onHandleIntent
import com.google.android.gms.location.FusedLocationProviderApi; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
if (intent != null) {
final String action = intent.getAction();
if (MainActivity.ACTION_CHECK_LOCATION.equals(action)) {
final Location location = intent.getParcelableExtra(
FusedLocationProviderApi.KEY_LOCATION_CHANGED);
handleActionCheckLocation(location);
}
else if (MainActivity.ACTION_START_NORMAL_UPDATES.equals(action)) {
handleActionChangeToNormalUpdates();
}
else if (MainActivity.ACTION_START_FAST_UPDATES.equals(action)) {
handleActionStartFastUpdates();
}
}
}
示例5: onHandleIntent
import com.google.android.gms.location.FusedLocationProviderApi; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
if (intent != null) {
final String action = intent.getAction();
if (MainActivity.ACTION_CHECK_LOCATION.equals(action)) {
final Location location = intent.getParcelableExtra(
FusedLocationProviderApi.KEY_LOCATION_CHANGED);
handleActionCheckLocation(location);
}
else if (MainActivity.ACTION_START_NORMAL_UPDATES.equals(action)) {
handleActionStartNormalUpdates();
}
else if (MainActivity.ACTION_START_FAST_UPDATES.equals(action)) {
handleActionChangeToFastUpdates();
}
}
}
示例6: setup
import com.google.android.gms.location.FusedLocationProviderApi; //导入依赖的package包/类
@Before
public void setup() {
lp = spy(LocationPublisher.class);
lp.mGoogClient = mock(GoogleApiClient.class);
lp.mLocProvider = mock(FusedLocationProviderApi.class);
shadowOf(RuntimeEnvironment.application)
.setComponentNameAndServiceForBindService(
new ComponentName("org.tlc.whereat.modules.pubsub", "LocationPublisher"),
mock(IBinder.class));
lp.mPrefs = ShadowPreferenceManager.getDefaultSharedPreferences(RuntimeEnvironment.application);
lp.mPrefListener = lp.buildPrefListener();
lp.mPrefs.registerOnSharedPreferenceChangeListener(lp.mPrefListener);
}
示例7: poll_turnsOnPolling
import com.google.android.gms.location.FusedLocationProviderApi; //导入依赖的package包/类
@Test
public void poll_turnsOnPolling() {
lp.mLocProvider = mock(FusedLocationProviderApi.class);
lp.poll();
verify(lp.mLocProvider).requestLocationUpdates(lp.mGoogClient, lp.mLocReq, lp);
assertThat(lp.mPolling).isTrue();
}
示例8: stopPolling_stopsPolling
import com.google.android.gms.location.FusedLocationProviderApi; //导入依赖的package包/类
@Test
public void stopPolling_stopsPolling() {
lp.mLocProvider = mock(FusedLocationProviderApi.class);
lp.stopPolling();
verify(lp.mLocProvider).removeLocationUpdates(lp.mGoogClient, lp);
assertThat(lp.mPolling).isFalse();
}
示例9: setupMockLocationService
import com.google.android.gms.location.FusedLocationProviderApi; //导入依赖的package包/类
static LocationPublisher setupMockLocationService(){
LocationPublisher lp = spy(LocationPublisher.class);
lp.mGoogClient = mock(GoogleApiClient.class);
lp.mLocProvider = mock(FusedLocationProviderApi.class);
bindService();
return lp;
}
示例10: requestLocationInternal
import com.google.android.gms.location.FusedLocationProviderApi; //导入依赖的package包/类
/**
* Called when a location update is requested
*/
private void requestLocationInternal() {
Log.v(TAG, ACTION_REQUEST_LOCATION);
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.build();
// It's OK to use blockingConnect() here as we are running in an
// IntentService that executes work on a separate (background) thread.
ConnectionResult connectionResult = googleApiClient.blockingConnect(
Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS);
if (connectionResult.isSuccess() && googleApiClient.isConnected()) {
Intent locationUpdatedIntent = new Intent(this, UtilityService.class);
locationUpdatedIntent.setAction(ACTION_LOCATION_UPDATED);
// Send last known location out first if available
Location location = FusedLocationApi.getLastLocation(googleApiClient);
if (location != null) {
Intent lastLocationIntent = new Intent(locationUpdatedIntent);
lastLocationIntent.putExtra(
FusedLocationProviderApi.KEY_LOCATION_CHANGED, location);
startService(lastLocationIntent);
}
// Request new location
LocationRequest mLocationRequest = new LocationRequest()
.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
FusedLocationApi.requestLocationUpdates(
googleApiClient, mLocationRequest,
PendingIntent.getService(this, 0, locationUpdatedIntent, 0));
googleApiClient.disconnect();
} else {
Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG,
connectionResult.getErrorCode()));
}
}
示例11: onReceive
import com.google.android.gms.location.FusedLocationProviderApi; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
Location location =
intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED);
if (location != null) {
mLatestLocation = new LatLng(location.getLatitude(), location.getLongitude());
mAdapter.mAttractionList = loadAttractionsFromLocation(mLatestLocation);
mAdapter.notifyDataSetChanged();
}
}
示例12: create
import com.google.android.gms.location.FusedLocationProviderApi; //导入依赖的package包/类
@Override
public FusedLocationProviderApi create() {
return LocationServices.FusedLocationApi;
}
示例13: create
import com.google.android.gms.location.FusedLocationProviderApi; //导入依赖的package包/类
@Override
public FusedLocationProviderApi create() {
return new MockFusedLocationProvider();
}
示例14: LocationProviderGmsCore
import com.google.android.gms.location.FusedLocationProviderApi; //导入依赖的package包/类
LocationProviderGmsCore(GoogleApiClient client, FusedLocationProviderApi locationApi) {
mGoogleApiClient = client;
mLocationProviderApi = locationApi;
}
示例15: onHandleIntent
import com.google.android.gms.location.FusedLocationProviderApi; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
//String className = intent.getStringExtra("backgroundClass");
final android.location.Location location = intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED);
if (AndroidLocationPlayServiceManager.inMemoryBackgroundLocationListener != null) {
// This is basically just a short-term location request and we are using the in-memory listeners.
AndroidLocationPlayServiceManager mgr = AndroidLocationPlayServiceManager.inMemoryBackgroundLocationListener;
mgr.onLocationChanged(location);
return;
}
if (intent.getDataString() == null) {
System.out.println("BackgroundLocationHandler received update without data string.");
return;
}
String[] params = intent.getDataString().split("[?]");
//might happen on some occasions, no need to do anything.
if (location == null) {
return;
}
//if the Display is not initialized we need to launch the CodenameOneBackgroundLocationActivity
//activity to handle this
boolean shouldStopWhenDone = false;
if (!Display.isInitialized()) {
shouldStopWhenDone = true;
AndroidImplementation.startContext(this);
//Display.init(this);
/*
Intent bgIntent = new Intent(getBaseContext(), CodenameOneBackgroundLocationActivity.class);
Bundle b = new Bundle();
b.putString("backgroundLocation", params[1]);
b.putParcelable("Location", location);
bgIntent.putExtras(b); //Put your id to your next Intent
bgIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(bgIntent);
*/
} //else {
try {
//the 2nd parameter is the class name we need to create
LocationListener l = (LocationListener) Class.forName(params[1]).newInstance();
l.locationUpdated(AndroidLocationManager.convert(location));
} catch (Exception e) {
Log.e("Codename One", "background location error", e);
}
if (shouldStopWhenDone) {
AndroidImplementation.stopContext(this);
}
//}
}