本文整理了Java中android.location.LocationManager.getAllProviders()
方法的一些代码示例,展示了LocationManager.getAllProviders()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocationManager.getAllProviders()
方法的具体详情如下:
包路径:android.location.LocationManager
类名称:LocationManager
方法名:getAllProviders
暂无
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldReturnAllProviders() throws Exception {
assertThat(locationManager.getAllProviders().size()).isEqualTo(3);
shadowLocationManager.setProviderEnabled("MY_PROVIDER", false);
assertThat(locationManager.getAllProviders().size()).isEqualTo(4);
}
代码示例来源:origin: stackoverflow.com
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
String provider = locationManager.getBestProvider(new Criteria(), true);
Location locations = locationManager.getLastKnownLocation(provider);
List<String> providerList = locationManager.getAllProviders();
if(null!=locations && null!=providerList && providerList.size()>0){
double longitude = locations.getLongitude();
double latitude = locations.getLatitude();
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
try {
List<Address> listAddresses = geocoder.getFromLocation(latitude, longitude, 1);
if(null!=listAddresses&&listAddresses.size()>0){
String _Location = listAddresses.get(0).getAddressLine(0);
}
} catch (IOException e) {
e.printStackTrace();
}
}
代码示例来源:origin: stackoverflow.com
for (String s : locationManager.getAllProviders()) {
locationManager.requestLocationUpdates(s, checkInterval,
minDistance, new LocationListener() {
代码示例来源:origin: DaxiaK/MyDiary
private void openGPSListener() {
progressDialog.show();
try {
if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)) {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}
if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER)) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
}
//Waiting gps max timeout is 20s
diaryHandler.sendEmptyMessageDelayed(0, GPS_TIMEOUT);
} catch (SecurityException e) {
//do nothing
}
}
代码示例来源:origin: DaxiaK/MyDiary
try {
if (theFrag.diaryLocations != null) {
List<String> providerList = theFrag.locationManager.getAllProviders();
if (null != theFrag.diaryLocations && null != providerList && providerList.size() > 0) {
double longitude = theFrag.diaryLocations.getLongitude();
代码示例来源:origin: DaxiaK/MyDiary
try {
if (theFrag.diaryLocations != null) {
List<String> providerList = theFrag.locationManager.getAllProviders();
if (null != theFrag.diaryLocations && null != providerList && providerList.size() > 0) {
double longitude = theFrag.diaryLocations.getLongitude();
代码示例来源:origin: bfabiszewski/ulogger-android
/**
* Check if given provider exists on device
* @param provider Provider
* @return True if exists, false otherwise
*/
private boolean providerExists(String provider) {
return locManager.getAllProviders().contains(provider);
}
代码示例来源:origin: behindeye/WxPhoneNumberHelper
public static boolean hasNetworkLocationDevice(Context context) {
final LocationManager mgr = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
if (mgr == null) {
return false;
}
final List<String> providers = mgr.getAllProviders();
if (providers == null) {
return false;
}
return providers.contains(LocationManager.NETWORK_PROVIDER);
}
代码示例来源:origin: behindeye/WxPhoneNumberHelper
public static boolean hasGPSDevice(Context context) {
final LocationManager mgr = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
if (mgr == null) {
return false;
}
final List<String> providers = mgr.getAllProviders();
if (providers == null) {
return false;
}
return providers.contains(LocationManager.GPS_PROVIDER);
}
代码示例来源:origin: stackoverflow.com
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = null;
List providers = lm.getAllProviders();
for (Object provider : providers) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
Location loc = lm.getLastKnownLocation((String) provider);
if (provider.equals(TEST_MOCK_GPS_LOCATION)) {
mLastLocation = loc;
}
}
代码示例来源:origin: stackoverflow.com
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Intent intent = new Intent(context, LocationReceiver.class);
pendingIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT);
List<String> knownProviders = locationManager.getAllProviders();
if(locationManager != null && pendingIntent != null && knownProviders.contains(LocationManager.GPS_PROVIDER)){
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MINUTE_INTERVAL*5, 0, pendingIntent);
}
if(locationManager != null && pendingIntent != null && knownProviders.contains(LocationManager.NETWORK_PROVIDER)){
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MINUTE_INTERVAL*5, 0, pendingIntent);
}
代码示例来源:origin: stackoverflow.com
LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
List<String> providers = manager.getAllProviders();
Location loc;
for (int i = 0; i < providers.size(); i++) {
loc = manager.getLastKnownLocation(providers.get(i));
loc.getTime();
/*
* put your code here
* compare loc from providers to get the most
* recent location
*/
}
}
代码示例来源:origin: tyrex-team/senslogs
@Override
public boolean exists(Context context) {
return getLocationManager(context).getAllProviders().contains(getLocationProvider());
}
代码示例来源:origin: WangDaYeeeeee/GeometricWeather
private boolean updateLocation() {
if (!TextUtils.isEmpty(provider)
&& locationManager.getAllProviders().contains(provider)) {
Location l = locationManager.getLastKnownLocation(provider);
if (l != null) {
location = l;
}
Result result = buildResult();
if (result != null) {
dispatchResult(result);
return true;
}
}
return false;
}
代码示例来源:origin: ShowMeHills/ShowMeHills
public void switchOn() {
if (!LocationFinderState.Active.equals(state)) {
mLocationManager = mixContext.GetLocationManager();
locationResolvers.clear();
for (String p : mLocationManager.getAllProviders())
{
if(mLocationManager.isProviderEnabled(p))
{
LocationResolver lr = new LocationResolver(mLocationManager, p, this);
locationResolvers.add(lr);
}
}
state = LocationFinderState.Confused;
}
}
代码示例来源:origin: stackoverflow.com
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
String provider = locationManager.getBestProvider(new Criteria(), true);
Location locations = locationManager.getLastKnownLocation(provider);
List<String> providerList = locationManager.getAllProviders();
if(null!=locations && null!=providerList && providerList.size()>0){
double longitude = locations.getLongitude();
double latitude = locations.getLatitude();
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
try {
List<Address> listAddresses = geocoder.getFromLocation(latitude, longitude, 1);
if(null!=listAddresses&&listAddresses.size()>0){
String _Location = listAddresses.get(0).getAddressLine(1);
}
} catch (IOException e) {
e.printStackTrace();
}
代码示例来源:origin: stackoverflow.com
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
String provider = locationManager.getBestProvider(new Criteria(), true);
Location locations = locationManager.getLastKnownLocation(provider);
List<String> providerList = locationManager.getAllProviders();
if(null!=locations && null!=providerList && providerList.size()>0){
double longitude = locations.getLongitude();
double latitude = locations.getLatitude();
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
try {
List<Address> listAddresses = geocoder.getFromLocation(latitude, longitude, 1);
if(null!=listAddresses&&listAddresses.size()>0){
String _Location = listAddresses.get(0).getAddressLine(0);
}
} catch (IOException e) {
e.printStackTrace();
}
}
代码示例来源:origin: thuryn/your-local-weather
private boolean gpsRequestLocation() {
boolean isGPSEnabled = AppPreference.isGpsEnabledByPreferences(getBaseContext()) &&
locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER)
&& locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (isGPSEnabled && ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
Looper locationLooper = Looper.myLooper();
appendLog(getBaseContext(), TAG, "get location from GPS");
timerHandlerGpsLocation.postDelayed(timerRunnableGpsLocation, GPS_LOCATION_TIMEOUT_IN_MS);
locationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, gpsLocationListener, locationLooper);
startRefreshRotation("gpsRequestLocation", 3);
return true;
} else {
return false;
}
}
代码示例来源:origin: stackoverflow.com
LocationManager location_manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
LocationListener listner = new MyLocationListener();
boolean networkLocationEnabled = location_manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
boolean gpsLocationEnabled = location_manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (networkLocationEnabled || gpsLocationEnabled) {
if (location_manager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER) && networkLocationEnabled) {
location_manager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 2000, 2000, listner);
location_manager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
} else if (location_manager.getAllProviders().contains(LocationManager.GPS_PROVIDER) && gpsLocationEnabled) {
location_manager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 2000, 2000, listner);
location_manager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
代码示例来源:origin: Phantast/smartnavi
public void startLocationUpdates() {
GoogleApiAvailability api = GoogleApiAvailability.getInstance();
int status = api.isGooglePlayServicesAvailable(mContext);
if (status != ConnectionResult.SUCCESS) {
try {
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10, 0, this);
if (mLocationManager.getAllProviders().contains("network")) {
mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10, 0, this);
}
mLocationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 10, 0, this);
} catch (SecurityException e) {
e.printStackTrace();
}
} else {
// get first position
mGoogleApiClient.connect();
}
}
内容来源于网络,如有侵权,请联系作者删除!