本文整理了Java中android.location.LocationManager.setTestProviderEnabled()
方法的一些代码示例,展示了LocationManager.setTestProviderEnabled()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocationManager.setTestProviderEnabled()
方法的具体详情如下:
包路径:android.location.LocationManager
类名称:LocationManager
方法名:setTestProviderEnabled
暂无
代码示例来源:origin: Phantast/smartnavi
public static void reactivateFakeProvider() {
if (BuildConfig.debug)
Log.i("Location-Status", "reactivate Fake Provider");
try {
mocLocationProvider = LocationManager.GPS_PROVIDER;
geoLocationManager.addTestProvider(mocLocationProvider, false, false, false, false, true, true, true, 0, 5);
geoLocationManager.setTestProviderEnabled(mocLocationProvider, true);
} catch (Exception e) {
e.printStackTrace();
}
}
代码示例来源:origin: johncarpenter/Android-GPX-Mock-Location-Provider
private void setupTestProvider() {
mLocationManager.addTestProvider(PROVIDER_NAME, false, //requiresNetwork,
false, // requiresSatellite,
false, // requiresCell,
false, // hasMonetaryCost,
false, // supportsAltitude,
false, // supportsSpeed, s
false, // upportsBearing,
Criteria.POWER_LOW, // powerRequirement
Criteria.ACCURACY_FINE); // accuracy
mLocationManager.setTestProviderEnabled("gps", true);
}
代码示例来源:origin: luv/mockgeofix
protected void _register() {
// if the test provider already exists, android handles this fine
try {
mLocationManager.addTestProvider(locationProviderName, false, false, false,
false, true, true, true, 0, accuracy);
mLocationManager.setTestProviderEnabled(locationProviderName, true);
} catch (IllegalArgumentException ex) {
Log.e(TAG, "IllegalArgumentException thrown in _register");
}
}
代码示例来源:origin: amotzte/android-mock-location-for-development
MockLocationProvider(String name, Context ctx) {
this.providerName = name;
this.ctx = ctx;
LocationManager lm = (LocationManager) ctx.getSystemService(
Context.LOCATION_SERVICE);
lm.addTestProvider(providerName, false, false, false, false, false,
true, true, 0, 5);
lm.setTestProviderEnabled(providerName, true);
}
代码示例来源:origin: openxc/openxc-android
private void overwriteNativeProvider() {
if(mOverwriteNativeStatus && !mNativeGpsOverridden && mLocationManager != null) {
try {
mLocationManager.addTestProvider(LocationManager.GPS_PROVIDER,
false, false, false, false, false, true, false, 0, 5);
mLocationManager.setTestProviderEnabled(
LocationManager.GPS_PROVIDER, true);
} catch(SecurityException e) {
Log.w(TAG, "Unable to use mocked locations, " +
"insufficient privileges - make sure mock locations " +
"are allowed in device settings", e);
}
}
}
代码示例来源:origin: Phantast/smartnavi
public static void pauseFakeProvider() {
if (BuildConfig.debug)
Log.i("Location-Status", "pause Fake Provider");
try {
geoLocationManager.setTestProviderEnabled(mocLocationProvider, false);
geoLocationManager.removeTestProvider(mocLocationProvider);
geoLocationManager.clearTestProviderEnabled(mocLocationProvider);
} catch (Exception e) {
e.printStackTrace();
}
}
代码示例来源:origin: openxc/openxc-android
private void setupMockLocations() {
try {
if(mLocationManager.getProvider(
VEHICLE_LOCATION_PROVIDER) == null) {
mLocationManager.addTestProvider(VEHICLE_LOCATION_PROVIDER,
false, false, false, false, false, true, false, 0, 5);
}
mLocationManager.setTestProviderEnabled(
VEHICLE_LOCATION_PROVIDER, true);
} catch(SecurityException e) {
Log.w(TAG, "Unable to use mocked locations, " +
"insufficient privileges - make sure mock locations " +
"are allowed in device settings", e);
mLocationManager = null;
}
}
}
代码示例来源:origin: Phantast/smartnavi
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
if (shouldStart == false) {
try {
geoLocationManager.setTestProviderEnabled(mocLocationProvider, false);
geoLocationManager.removeTestProvider(mocLocationProvider);
geoLocationManager.clearTestProviderEnabled(mocLocationProvider);
} catch (Exception e) {
e.printStackTrace();
}
notificationManager.cancelAll();
Toast.makeText(this, getApplicationContext().getResources().getString(R.string.tx_70), Toast.LENGTH_LONG).show();
}
finish();
return (true);
default:
return super.onOptionsItemSelected(item);
}
}
代码示例来源:origin: stackoverflow.com
public void testGPS() {
LocationManager lm = (LocationManager) mActivity
.getSystemService(Context.LOCATION_SERVICE);
lm.setTestProviderEnabled(LocationManager.GPS_PROVIDER, true);
lm.setTestProviderStatus(LocationManager.GPS_PROVIDER,
LocationProvider.AVAILABLE,
null, System.currentTimeMillis());
Location location = new Location(LocationManager.GPS_PROVIDER);
location.setLatitude(1.0);
location.setLongitude(2.0);
location.setTime(System.currentTimeMillis());
lm.setTestProviderLocation(LocationManager.GPS_PROVIDER, location);
try {
Thread.sleep(2000);
} catch(InterruptedException e) {
}
}
代码示例来源:origin: johncarpenter/Android-GPX-Mock-Location-Provider
private void disableGpsProvider() {
if (mLocationManager.getProvider(PROVIDER_NAME) != null) {
mLocationManager.setTestProviderEnabled(PROVIDER_NAME, false);
mLocationManager.clearTestProviderEnabled(PROVIDER_NAME);
mLocationManager.clearTestProviderLocation(PROVIDER_NAME);
mLocationManager.removeTestProvider(PROVIDER_NAME);
}
}
代码示例来源:origin: stackoverflow.com
mLocationManager.addTestProvider(GPS_PROVIDER, false, false, false,
false, false, true, true, 0, 5);
mLocationManager.setTestProviderEnabled(GPS_PROVIDER, true);
代码示例来源:origin: stackoverflow.com
public void test1_TestCaseFoo()
{
Location location = new Location("network");
location.setLatitude(-15.83554363);
location.setLongitude(-48.01770782);
location.setTime(new Date().getTime());
location.setAccuracy(100.0f);
location.setElapsedRealtimeNanos(System.nanoTime());
LocationManager locationManager = (LocationManager) getInstrumentation().getTargetContext().getSystemService(Context.LOCATION_SERVICE);
locationManager.addTestProvider(LocationManager.GPS_PROVIDER, false, false, false, false, true, true, true, Criteria.POWER_LOW, Criteria.ACCURACY_FINE);
locationManager.setTestProviderStatus(LocationManager.GPS_PROVIDER, LocationProvider.AVAILABLE, null, System.currentTimeMillis());
locationManager.setTestProviderEnabled(LocationManager.GPS_PROVIDER, true);
locationManager.setTestProviderLocation(LocationManager.GPS_PROVIDER, location);
locationManager.addTestProvider(LocationManager.NETWORK_PROVIDER, false, false, false, false, true, true, true, Criteria.POWER_LOW, Criteria.ACCURACY_FINE);
locationManager.setTestProviderStatus(LocationManager.NETWORK_PROVIDER, LocationProvider.AVAILABLE, null, System.currentTimeMillis());
locationManager.setTestProviderEnabled(LocationManager.NETWORK_PROVIDER, true);
locationManager.setTestProviderLocation(LocationManager.NETWORK_PROVIDER, location);
mActivity = getActivity();
....
代码示例来源:origin: Phantast/smartnavi
try {
geoLocationManager.addTestProvider(mocLocationProvider, false, false, false, false, true, true, true, 1, 5);
geoLocationManager.setTestProviderEnabled(mocLocationProvider, true);
geoLocationManager.setTestProviderStatus(mocLocationProvider, 2, null, System.currentTimeMillis());
代码示例来源:origin: Phantast/smartnavi
public void stop() {
//stop the Handlers who are responsible for restarting the sensor-listeners
mTracker.send(new HitBuilders.EventBuilder()
.setCategory("Action")
.setAction("Backround_service_stopped")
.build());
GoogleMap.listHandler.removeMessages(10);
Config.backgroundServiceActive = false;
try {
geoLocationManager.setTestProviderEnabled(mocLocationProvider, false);
} catch (Exception e) {
// e.printStackTrace();
}
try {
geoLocationManager.clearTestProviderEnabled(mocLocationProvider);
} catch (Exception e) {
// e.printStackTrace();
}
try {
geoLocationManager.removeTestProvider(mocLocationProvider);
} catch (Exception e) {
// e.printStackTrace();
}
notificationManager.cancelAll();
Toast.makeText(this, getApplicationContext().getResources().getString(R.string.tx_70), Toast.LENGTH_LONG).show();
finish();
}
代码示例来源:origin: Phantast/smartnavi
geoLocationManager.setTestProviderEnabled(mocLocationProvider, false);
} catch (Exception e2) {
代码示例来源:origin: stackoverflow.com
locationManager.setTestProviderEnabled(GPS_MOCK_PROVIDER, true);
代码示例来源:origin: xbenjii/PokeMock
mLocationManager.setTestProviderEnabled(mockLocationProvider, true);
mLocationManager.setTestProviderStatus(mockLocationProvider, LocationProvider.AVAILABLE, null, System.currentTimeMillis());
if(ContextCompat.checkSelfPermission(this,
代码示例来源:origin: org.seleniumhq.selenium/selenium-android-driver
locManager.addTestProvider(locationProvider,
true, true, true, true, true, true, true, 0, 5);
locManager.setTestProviderEnabled(locationProvider, true);
locManager.requestLocationUpdates(locationProvider, 0, 0, this);
} catch (SecurityException e) {
代码示例来源:origin: stackoverflow.com
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy( Criteria.ACCURACY_FINE );
String mocLocationProvider = LocationManager.GPS_PROVIDER;//lm.getBestProvider( criteria, true );
if ( mocLocationProvider == null ) {
Toast.makeText(getApplicationContext(), "No location provider found!", Toast.LENGTH_SHORT).show();
return;
}
lm.addTestProvider(mocLocationProvider, false, false,
false, false, true, true, true, 0, 5);
lm.setTestProviderEnabled(mocLocationProvider, true);
Location loc = new Location(mocLocationProvider);
Location mockLocation = new Location(mocLocationProvider); // a string
mockLocation.setLatitude(-26.902038); // double
mockLocation.setLongitude(-48.671337);
mockLocation.setAltitude(loc.getAltitude());
mockLocation.setTime(System.currentTimeMillis());
mockLocation.setAccuracy(1);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
mockLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
}
lm.setTestProviderLocation( mocLocationProvider, mockLocation);
Toast.makeText(getApplicationContext(), "Working", Toast.LENGTH_SHORT).show();
内容来源于网络,如有侵权,请联系作者删除!