How do I get started on manipulating android GPS?

46 views Asked by At

So I've been trying to learn more about Android GPS applications (specifically offline) and I've come to notice a LocationManager might be able to solve my issues. Problem is that it requires API 23 in order to function and I'd like to target API 19 devices for a specific reason. Is there any other way to manipulate the GPS function to get coordinates without internet access on a lower level API?

Please help!

@Edit: I've added a sample application that I made (and is working just fine - the only problem here is that it requires API 23 in order to run) This piece of code describes an application that displays decimal coordinates every 5 seconds.

button = (Button) findViewById(R.id.button); textView = (TextView) findViewById(R.id.textView);

    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    locationListener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            textView.append("\n "+ location.getLatitude() + " "+ location.getLongitude());
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {

        }

        @Override
        public void onProviderEnabled(String provider) {

        }

        @Override
        public void onProviderDisabled(String provider) {
            Intent intent = new Intent (Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivity(intent);
        }
    };
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(new String[]{
                    Manifest.permission.ACCESS_FINE_LOCATION
            }, 10 );
        }
        return;
    }
    else {
        configureButton();
    }



} //onCreate

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    switch (requestCode) {
        case 10:
            if (grantResults.length>0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
                configureButton();
            return;
    }
}

private void configureButton() {
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            locationManager.requestLocationUpdates("gps", 5000, 0, locationListener);
        }
    });

}
0

There are 0 answers