我正在開發的應用程序的用戶需要在註冊過程中共享位置。點擊「定位我」按鈕應該得到GPS座標(或任何提供的,我還不知道)。清單文件中列出的權限的Android安全例外
當單擊該按鈕時,我收到此錯誤信息:
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();
}
}
}
可能的重複http://stackoverflow.com/questions/32083913/android-gps-requires-access-fine-location-error-even-though-my-manifest-file –
看到這[鏈接](http://stackoverflow.com/questions/32083913/android-gps-requires-access-fine-location-error-even-though-my-manifest-file)它可以幫助你!希望你喜歡 –
檢查你的目標api是23嗎?@丹 – Lampard