我正在开发的应用的用户需要在注册过程中共享该位置。单击"找到我"按钮应该获得GPS坐标(或者提供的任何东西,我还不知道)。
单击该按钮时,收到以下错误消息:
java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission.
根据我的理解,这与在清单文件中列出权限有关。但许可就在那里。
我发现有类似问题的主题建议从我正在测试它的设备上卸载应用程序,清理和重建项目。我做了所有这些,但问题仍然存在。我必须遗漏其他东西,可能非常明显。有什么想法吗?
谢谢!
这是我的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest package = "com.iskillu.iskillu"
xmlns:android = "http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<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:label = "@string/app_name"
android:theme = "@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name = "android.intent.action.MAIN" />
<category android:name = "android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information.
-->
<meta-data
android:name = "com.google.android.gms.version"
android:value = "@integer/google_play_services_version" />
<activity
android:name = ".JoinActivity"
android:label = "@string/title_activity_join"
android:theme = "@style/AppTheme.NoActionBar">
</activity>
<activity
android:name = ".LoginActivity"
android:label = "@string/title_activity_login"
android:theme = "@style/AppTheme.NoActionBar">
</activity>
<activity android:name = ".RegistrationSuccessfulActivity">
<intent-filter>
<action android:name = "android.intent.action.VIEW" />
<category android:name = "android.intent.category.DEFAULT" />
<category android:name = "android.intent.category.BROWSABLE" />
<data android:scheme = "http" />
<data android:scheme = "https" />
<data android:host = "www.iskillu.com" />
<data android:host = "iskillu.com" />
</intent-filter>
</activity>
<activity android:name = ".presentation.PresentationActivity">
</activity>
</application>
</manifest>
这是执行时抛出异常的方法:
public void getGpsLocation ( View view )
{
LocationManager locationManager = ( LocationManager ) this.getSystemService( Context.LOCATION_SERVICE );
boolean isProviderEnabled = locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER);
if ( ! locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER) )
{
Toast.makeText ( this.getApplicationContext (), R.string.enable_gps, Toast.LENGTH_LONG ).show () ;
}
else
{
try {
Location myLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (myLocation != null)
{
Log.d("TAG", "Not null");
}
else
{
Log.d("TAG", "NULL");
}
}
catch (SecurityException se) {
Log.d("TAG", "SE CAUGHT");
se.printStackTrace();
}
}
}