use of android.location.LocationListener in project android_frameworks_base by crdroidandroid.
the class ExternalSharedPermsFLTest method testRunFineLocation.
/** The use of location manager below is simply to simulate an app that
* tries to use it, so we can verify whether permissions are granted and accessible.
* */
public void testRunFineLocation() {
LocationManager locationManager = (LocationManager) getInstrumentation().getContext().getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
public void onLocationChanged(Location location) {
}
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
});
}
use of android.location.LocationListener in project RxTools by vondear.
the class ActivityBaseLocation method getLocation.
// ==============================================================================================检测GPS是否已打开 end
private void getLocation() {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(mContext, new String[] { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION }, 1);
return;
}
mLocationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
mLongitude = location.getLongitude();
mLatitude = location.getLatitude();
setGpsInfo(location);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
switch(status) {
// GPS状态为可见时
case LocationProvider.AVAILABLE:
break;
// GPS状态为服务区外时
case LocationProvider.OUT_OF_SERVICE:
RxToast.normal("当前GPS信号弱");
RxVibrateTool.vibrateOnce(mContext, 3000);
break;
// GPS状态为暂停服务时
case LocationProvider.TEMPORARILY_UNAVAILABLE:
break;
default:
break;
}
}
@Override
public void onProviderEnabled(String provider) {
RxToast.normal("当前GPS设备已打开");
RxVibrateTool.vibrateOnce(mContext, 800);
}
@Override
public void onProviderDisabled(String provider) {
RxToast.normal("当前GPS设备已关闭");
RxVibrateTool.vibrateOnce(mContext, 800);
gpsCheck();
}
};
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 0, mLocationListener);
}
use of android.location.LocationListener in project JavaForFun by gumartinm.
the class NextActivity method onCreate.
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CookieSyncManager.createInstance(this);
myCookie = CookieManager.getInstance().getCookie("users.mobiads.gumartinm.name");
setContentView(R.layout.nextactivity);
httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, ENCODED);
httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingAccuracy(Criteria.NO_REQUIREMENT);
criteria.setBearingRequired(false);
criteria.setCostAllowed(false);
criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
criteria.setSpeedAccuracy(Criteria.ACCURACY_LOW);
criteria.setSpeedRequired(true);
criteria.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
makeUseOfNewLocation(location);
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// 1. Find out the provider state. (see Copilot.java code GPSLocationListener)
// 2. If it is TEMPORARILY_UNAVAILABLE:
// 2.1. locationManager.removeUpdates(locationListener); <--- Stop wasting GPS or GSM connections
// 2.2. Launch Timer with TimerTask 30 or 60 seconds before to enable the locationManager to find out if the provider status changed.
// 3. If OUT_OF_SERVICE
// 3.1. locationManager.removeUpdates(locationListener); <--- Stop wasting GPS or GSM connections
// 3.2. Launch Timer with TimerTask 30 or 60 seconds before to enable the locationManager to find out if the provider status changed.
// 4. If AVAILABLE
// Nothing to do here.
// Just when we are in the second or third point we have to stop draining battery because it is useless.
}
public void onProviderEnabled(String provider) {
}
public void onProviderDisabled(String provider) {
}
};
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(0, 10, criteria, locationListener, null);
// Al parecer si pongo esto aqui, el servicio es enlazado nada mas iniciarse la aplicacion
// incluso cuando todavia estoy en la activity que hace login (la Test3Activity)
// ¿Se lanza el onCreate de una activity incluso antes de usar esa activity? ¿Por qué?
// ¿Quizás porque está declarada en el Manifest?
// mCallbackText = new TextView(this);
// this.doBindService();
}
Aggregations