No Reply No Reply - 1 year ago 100
Android Question

Android Secure the Location test

Hello everyone I am curious about how can I solve the location security problem in my code below:

private void myLocaion(){
Criteria criteria = new Criteria();
locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
final String myBestProvider = locationManager.getBestProvider(criteria, false);
Toast.makeText(gtApplicationContext(), myBestProvider, Toast.LENTH_SHORT).show();

myLocationListener = new LocationListener{

public void onLocationChaned(Location location){
location.getLatitude() + " " +
location.getLongiude(), Toast.LENGTH_SHORT).show();
public void onStatusChanged(String provider, int status, Bundle extras){}
public void onProviderEnabled(String provider){}
public void onProviderDisabled(String provider){}
locationManager.requestLocationUpdates(MyBestProvider, 0, 0, myLocationListener)


It seems that development environment of Android Studio declaration on the security issue on this code:

locationManager.requestLocationUpdates(MyBestProvider, 0, 0, myLocationListener)

Android API: 23

Answer Source

Android API 23 Requires a security review before the operation code

There is 3 ways to solve this problem:

1) Try to give the development environment to repair the security code requirement

2) To compile an older development environment Android Studio

3) Change the version of the target

Here is how to Change:

File -> project Structure.. -> Flavors-> Targer Sdk Version Change SDK Version If everything is correct until now, You can advance in writing application And send the location information method onLocationChanged( ) To map function :

Uri.parse("geo:" + myLocation.getLatitude() + "," myLocation.getLongitude())

And then :

public void showMap( Uri geoLocation ){
    Intent intent = new Intent (Intent.ACTION_VIEW); 
    if (intent.resolveActivity(getPackageManager()) != null){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download