use of android.location.Criteria in project weex-example by KalicyZhou.
the class DefaultLocation method findLocation.
private WXLocationListener findLocation(String watchId, String sucCallback, String errorCallback, boolean enableHighAccuracy, boolean enableAddress) {
if (mLocationManager == null) {
mLocationManager = (LocationManager) mWXSDKInstance.getContext().getSystemService(Context.LOCATION_SERVICE);
}
Criteria criteria = new Criteria();
if (enableHighAccuracy) {
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
}
//String provider = locationManager.getBestProvider(criteria, false);
if (ActivityCompat.checkSelfPermission(mWXSDKInstance.getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mWXSDKInstance.getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
WXLocationListener WXLocationListener = new WXLocationListener(mLocationManager, mWXSDKInstance, watchId, sucCallback, errorCallback, enableAddress);
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME, MIN_DISTANCE, WXLocationListener);
mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME, MIN_DISTANCE, WXLocationListener);
return WXLocationListener;
} else {
Map<String, Object> options = new HashMap<>();
options.put(ERROR_CODE, ErrorCode.NO_PERMISSION_ERROR);
options.put(ERROR_MSG, ErrorMsg.NO_PERMISSION_ERROR);
WXSDKManager.getInstance().callback(mWXSDKInstance.getInstanceId(), errorCallback, options);
}
return null;
}
use of android.location.Criteria in project android_frameworks_base by DirtyUnicorns.
the class FusedPrintersProvider method onStartLoading.
@Override
protected void onStartLoading() {
if (DEBUG) {
Log.i(LOG_TAG, "onStartLoading() " + FusedPrintersProvider.this.hashCode());
}
mLocationManager.requestLocationUpdates(LocationRequest.create().setQuality(LocationRequest.POWER_LOW).setInterval(LOCATION_UPDATE_MS), this, Looper.getMainLooper());
Location lastLocation = mLocationManager.getLastLocation();
if (lastLocation != null) {
onLocationChanged(lastLocation);
}
// Jumpstart location with a single forced update
Criteria oneTimeCriteria = new Criteria();
oneTimeCriteria.setAccuracy(Criteria.ACCURACY_FINE);
mLocationManager.requestSingleUpdate(oneTimeCriteria, this, Looper.getMainLooper());
// The contract is that if we already have a valid,
// result the we have to deliver it immediately.
(new Handler(Looper.getMainLooper())).post(new Runnable() {
@Override
public void run() {
deliverResult(new ArrayList<>(mPrinters));
}
});
// Always load the data to ensure discovery period is
// started and to make sure obsolete printers are updated.
onForceLoad();
}
use of android.location.Criteria in project android_frameworks_base by DirtyUnicorns.
the class LocationManagerTest method testGetBestProviderPowerCriteria.
public void testGetBestProviderPowerCriteria() {
Criteria c = new Criteria();
c.setPowerRequirement(Criteria.POWER_HIGH);
String p = manager.getBestProvider(c, true);
assertNotNull(p);
c.setPowerRequirement(Criteria.POWER_MEDIUM);
p = manager.getBestProvider(c, true);
assertNotNull(p);
c.setPowerRequirement(Criteria.POWER_LOW);
p = manager.getBestProvider(c, true);
assertNotNull(p);
c.setPowerRequirement(Criteria.NO_REQUIREMENT);
p = manager.getBestProvider(c, true);
assertNotNull(p);
}
use of android.location.Criteria in project android_frameworks_base by ResurrectionRemix.
the class FusedPrintersProvider method onStartLoading.
@Override
protected void onStartLoading() {
if (DEBUG) {
Log.i(LOG_TAG, "onStartLoading() " + FusedPrintersProvider.this.hashCode());
}
if (getContext().checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
mLocationManager.requestLocationUpdates(LocationRequest.create().setQuality(LocationRequest.POWER_LOW).setInterval(LOCATION_UPDATE_MS), this, Looper.getMainLooper());
Location lastLocation = mLocationManager.getLastLocation();
if (lastLocation != null) {
onLocationChanged(lastLocation);
}
// Jumpstart location with a single forced update
Criteria oneTimeCriteria = new Criteria();
oneTimeCriteria.setAccuracy(Criteria.ACCURACY_FINE);
mLocationManager.requestSingleUpdate(oneTimeCriteria, this, Looper.getMainLooper());
}
// The contract is that if we already have a valid,
// result the we have to deliver it immediately.
(new Handler(Looper.getMainLooper())).post(new Runnable() {
@Override
public void run() {
deliverResult(new ArrayList<>(mPrinters));
}
});
// Always load the data to ensure discovery period is
// started and to make sure obsolete printers are updated.
onForceLoad();
}
use of android.location.Criteria in project android_frameworks_base by crdroidandroid.
the class LocationManagerTest method testGetBestProviderPowerCriteria.
public void testGetBestProviderPowerCriteria() {
Criteria c = new Criteria();
c.setPowerRequirement(Criteria.POWER_HIGH);
String p = manager.getBestProvider(c, true);
assertNotNull(p);
c.setPowerRequirement(Criteria.POWER_MEDIUM);
p = manager.getBestProvider(c, true);
assertNotNull(p);
c.setPowerRequirement(Criteria.POWER_LOW);
p = manager.getBestProvider(c, true);
assertNotNull(p);
c.setPowerRequirement(Criteria.NO_REQUIREMENT);
p = manager.getBestProvider(c, true);
assertNotNull(p);
}
Aggregations