use of android.location.LocationManager in project Space-Station-Tracker by Kiarasht.
the class Locations method Connected.
/**
* Lets find user's location.
*/
private void Connected() {
// Check if we have the right permissions
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, R.string.errorPermissionLocation, Toast.LENGTH_LONG).show();
return;
}
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
List<String> providers = locationManager.getProviders(true);
Location location = null;
for (int i = providers.size() - 1; i >= 0; i--) {
location = locationManager.getLastKnownLocation(providers.get(i));
if (location != null)
break;
}
// If we got something back start parsing
if (location != null) {
String url = "https://maps.googleapis.com/maps/api/staticmap?" + "center=LAT,LNG&" + "zoom=13&" + "scale=1&" + "size=640x640&" + "markers=color:red%7CLAT,LNG&" + "key=AIzaSyAtpWPhzhbtqTgofnQhAHjiG12MmrY2AAE";
mLatitude = String.valueOf(location.getLatitude());
mLongitude = String.valueOf(location.getLongitude());
url = url.replace("LAT", mLatitude);
url = url.replace("LNG", mLongitude);
try {
List<Address> matches = new Geocoder(this).getFromLocation(location.getLatitude(), location.getLongitude(), 1);
final Address bestMatch = (matches.isEmpty() ? null : matches.get(0));
if (bestMatch != null) {
String locationFormat = "";
if (!"null".equals(bestMatch.getLocality())) {
locationFormat += bestMatch.getLocality() + ", ";
}
if (!"null".equals(bestMatch.getAdminArea())) {
locationFormat += bestMatch.getAdminArea() + " ";
}
if (!"null".equals(bestMatch.getCountryCode())) {
locationFormat += bestMatch.getCountryCode() + " ";
}
if (!"null".equals(bestMatch.getPostalCode())) {
locationFormat += bestMatch.getPostalCode();
}
mTitleView.setText(locationFormat);
}
} catch (IOException e) {
e.printStackTrace();
}
Picasso.with(mActivity).load(url).into(mImageView);
displayResults();
displayPasses(null, null, null);
} else {
Toast.makeText(this, R.string.errorLocation, Toast.LENGTH_LONG).show();
}
}
use of android.location.LocationManager in project android_frameworks_base by ResurrectionRemix.
the class ExternalSharedPermsTest method testRunLocationAndBluetooth.
/** The use of location manager and bluetooth below are simply to simulate an app that
* tries to use them, so we can verify whether permissions are granted and accessible.
* */
public void testRunLocationAndBluetooth() {
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) {
}
});
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if ((mBluetoothAdapter != null) && (!mBluetoothAdapter.isEnabled())) {
mBluetoothAdapter.getName();
}
}
use of android.location.LocationManager in project android_frameworks_base by ResurrectionRemix.
the class ExternalSharedPermsDiffKeyTest method testRunBluetoothAndFineLocation.
/** The use of location manager and bluetooth below are simply to simulate an app that
* tries to use them, so we can verify whether permissions are granted and accessible.
* */
public void testRunBluetoothAndFineLocation() {
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) {
}
});
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if ((mBluetoothAdapter != null) && (!mBluetoothAdapter.isEnabled())) {
mBluetoothAdapter.getName();
}
fail("this app was signed by a different cert and should crash/fail to run by now");
}
use of android.location.LocationManager in project android_frameworks_base by ResurrectionRemix.
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.LocationManager in project android_frameworks_base by ResurrectionRemix.
the class TrackerService method stopListeners.
/**
* De-registers all location listeners, closes persistent storage
*/
protected synchronized void stopListeners() {
LocationManager lm = getLocationManager();
if (mListeners != null) {
for (LocationTrackingListener listener : mListeners) {
lm.removeUpdates(listener);
}
mListeners.clear();
}
mListeners = null;
// stop cell state listener
if (mTelephonyManager != null) {
mTelephonyManager.listen(mPhoneStateListener, 0);
}
// stop network/wifi listener
if (mNetwork != null) {
unregisterReceiver(mNetwork);
}
mNetwork = null;
mTrackerData = null;
if (mPrefListener != null) {
getPreferences().unregisterOnSharedPreferenceChangeListener(mPrefListener);
mPrefListener = null;
}
}
Aggregations