When I run the following code in Android Studio:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LocationManager lcmanager = (LocationManager) getSystemService(LOCATION_SERVICE);
List<String> listadeprovider = lcmanager.getAllProviders();
LocationProvider locationP;
for(int i = 0; i < listadeprovider.size(); i++)
{
locationP = lcmanager.getProvider(listadeprovider.get(i));
System.out.println("\nPrecisao: " + locationP.getAccuracy() + "\nSuporta Altitude: " + locationP.supportsAltitude() + "\nRecursos: " + locationP.getPowerRequirement() + "\n");
}
}
}
and I get the following error message stating that I have not added the ACCESS_FINE_LOCATION permission:
FATAL EXCEPTION: main
Process: com.example.sullyvan.k19treinamentos, PID: 16601
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sullyvan.k19treinamentos/com.example.sullyvan.k19treinamentos.MainActivity}: java.lang.SecurityException: "passive" location provider requires ACCESS_FINE_LOCATION permission.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.SecurityException: "passive" location provider requires ACCESS_FINE_LOCATION permission.
at android.os.Parcel.readException(Parcel.java:1599)
at android.os.Parcel.readException(Parcel.java:1552)
at android.location.ILocationManager$Stub$Proxy.getProviderProperties(ILocationManager.java:1031)
at android.location.LocationManager.getProvider(LocationManager.java:373)
at com.example.sullyvan.k19treinamentos.MainActivity.onCreate(MainActivity.java:26)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
I already added this permission in Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
Can anyone help me with the question?