本文整理汇总了Java中android.location.LocationManager.NETWORK_PROVIDER属性的典型用法代码示例。如果您正苦于以下问题:Java LocationManager.NETWORK_PROVIDER属性的具体用法?Java LocationManager.NETWORK_PROVIDER怎么用?Java LocationManager.NETWORK_PROVIDER使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.location.LocationManager
的用法示例。
在下文中一共展示了LocationManager.NETWORK_PROVIDER属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: provide
@Override
protected void provide() {
Looper.prepare();
locationManager = (LocationManager) this.getContext().getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
long minTime = 0;
float minDistance = 0;
String provider;
if (Geolocation.LEVEL_EXACT.equals(level)) {
provider = LocationManager.GPS_PROVIDER;
}
else {
provider = LocationManager.NETWORK_PROVIDER;
}
locationManager.requestLocationUpdates(provider, minTime, minDistance, locationListener);
Looper.loop();
}
示例2: refreshLastKnownLocation
/**
* Requests an updated location if the last known location is older than maxAge milliseconds.
*
* Note: this must be called only on the UI thread.
*/
@SuppressFBWarnings("LI_LAZY_INIT_UPDATE_STATIC")
static void refreshLastKnownLocation(Context context, long maxAge) {
ThreadUtils.assertOnUiThread();
// We're still waiting for a location update.
if (sListener != null) return;
LocationManager locationManager =
(LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location == null || getLocationAge(location) > maxAge) {
String provider = LocationManager.NETWORK_PROVIDER;
if (locationManager.isProviderEnabled(provider)) {
sListener = new SelfCancelingListener(locationManager);
locationManager.requestSingleUpdate(provider, sListener, null);
}
}
}
示例3: provide
@Override
protected void provide() {
Looper.prepare();
locationManager = (LocationManager) this.getContext().getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
long minTime = this.interval;
float minDistance = 0;
String provider;
if (Geolocation.LEVEL_EXACT.equals(level)) {
provider = LocationManager.GPS_PROVIDER;
}
else {
provider = LocationManager.NETWORK_PROVIDER;
}
locationManager.requestLocationUpdates(provider, minTime, minDistance, locationListener);
Looper.loop();
}
示例4: onCreate
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LogHelper.verboseLog(TAG,
"File name: \"" +
Thread.currentThread().getStackTrace()[2].getFileName() +
"\", Line number: " +
Thread.currentThread().getStackTrace()[2].getLineNumber() +
", Class name: \"" +
Thread.currentThread().getStackTrace()[2].getClassName() +
"\", Method name: \"" +
Thread.currentThread().getStackTrace()[2].getMethodName() +
"\"");
if (Configuration.sIsFeatureLocationAvailable) {
if (Configuration.sIsFeatureLocationNetworkAvailable) {
mNetworkProvider = LocationManager.NETWORK_PROVIDER;
}
if (Configuration.sIsFeatureLocationGpsAvailable) {
mGpsProvider = LocationManager.GPS_PROVIDER;
}
mPassiveProvider = LocationManager.PASSIVE_PROVIDER;
}
}
示例5: onConnected
@Override
public void onConnected(@Nullable Bundle bundle) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},1);
}
else {
locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
String locationProvider = LocationManager.NETWORK_PROVIDER;
// mLastLocation = locationManager.getLastKnownLocation(locationProvider);
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
if (mLastLocation != null) {
try {
Get_intent(); //Fetch Intent Values
}catch (Exception e){
Log.d(TAG, "onCreate: Intent Error");
}
}
}
startLocationUpdates();
}
示例6: getLocation
public void getLocation(Fragment fragment) {
this.fragment = fragment;
boolean locationPermissionFlag = util.checkPermission(locationPermissions,
activity);
if (locationPermissionFlag) {
fragment.requestPermissions(locationPermissions, Configure.LOCATION_PERMISSION_CODE);
}else{
locationManager = (LocationManager) activity.getSystemService(Context.
LOCATION_SERVICE);
String provider;
List<String> providerList = locationManager.getProviders(true);
if (providerList.contains(LocationManager.GPS_PROVIDER)) {
provider = LocationManager.GPS_PROVIDER;
} else if (providerList.contains(LocationManager.NETWORK_PROVIDER)) {
provider = LocationManager.NETWORK_PROVIDER;
} else {
Toast.makeText(activity, "请连接网络或打开GPS",
Toast.LENGTH_LONG).show();
return;
}
Location location = locationManager.getLastKnownLocation(provider);
locationManager.requestLocationUpdates(provider, 2000, 10, this);
if (location != null) {
getLocation(location);
}
}
}
示例7: initLocation
private void initLocation() {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
List<String> providers = mLocationManager.getProviders(true);
String locationProvider;
/**
* 如果首选GPS定位,会存在这种情况,上次GPS启动采集数据在A地,本次在B地需要定位,但用户恰好在室内无
* GPS信号,只好使用上次定位数据,就出现了地区级偏差。而网络定位则更具有实时性,在精度要求不高以及室内
* 使用场景更多的前提下,首选网络定位
*/
if (providers.contains(LocationManager.NETWORK_PROVIDER)) {
locationProvider = LocationManager.NETWORK_PROVIDER; // 首选网络定位
} else if (providers.contains(LocationManager.GPS_PROVIDER)) {
locationProvider = LocationManager.GPS_PROVIDER;
} else {
locationProvider = LocationManager.PASSIVE_PROVIDER;
}
if (mLocationListener != null)
mLocationManager.requestLocationUpdates(locationProvider, 2000, 10, mLocationListener);
}
示例8: getLocation
public Location getLocation() {
Location location = new Location(LocationManager.NETWORK_PROVIDER);
location.setLatitude(getLatitude());
location.setLongitude(getLongitude());
return location;
}
示例9: getValidProvider
@Nullable
private static String getValidProvider(LocationManager locationManager, boolean highAccuracy) {
String provider =
highAccuracy ? LocationManager.GPS_PROVIDER : LocationManager.NETWORK_PROVIDER;
if (!locationManager.isProviderEnabled(provider)) {
provider = provider.equals(LocationManager.GPS_PROVIDER)
? LocationManager.NETWORK_PROVIDER
: LocationManager.GPS_PROVIDER;
if (!locationManager.isProviderEnabled(provider)) {
return null;
}
}
return provider;
}
示例10: update
@Override
public void update() {
currentProvider = LocationManager.NETWORK_PROVIDER;
}