1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
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 = (LocationManager) getSystemService(LOCATION_SERVICE); try { locationManager.addNmeaListener(this.getMainExecutor(), new OnNmeaMessageListener{ @Override public void onNmeaMessage(String s, long l) { Log.d("LOCATION",l + "return " + s); } } ); } catch (IllegalArgumentException e) { Log.e("LOCATION", "something is null"); } catch (SecurityException e) { Log.e("LOCATION", "ACCESS_FINE_LOCATION permission is not present"); } LocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, new LocationListener() { @Override public void onLocationChanged(Location location) { Log.d("LOCATION_PROVIDER", "LihuaLog" + location.toString()); }
@Override public void onProviderEnabled(String provider) { Log.d("LOCATION_PROVIDER", "LihuaLog Enabled" + provider); }
@Override public void onProviderDisabled(String provider) { Log.d("LOCATION_PROVIDER", "LihuaLog Disabled" + provider); } }); }
|