2016-05-03 61 views
2

我正在開發的應用程序的用戶需要在註冊過程中共享位置。點擊「定位我」按鈕應該得到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(); 
       } 
      } 
     } 
+1

可能的重複http://stackoverflow.com/questions/32083913/android-gps-requires-access-fine-location-error-even-though-my-manifest-file –

+0

看到這[鏈接](http://stackoverflow.com/questions/32083913/android-gps-requires-access-fine-location-error-even-though-my-manifest-file)它可以幫助你!希望你喜歡 –

+0

檢查你的目標api是23嗎?@丹 – Lampard

回答

1

從版本的Android M開始,你將需要在運行時請求許可Requesting Permissions at Run Time

+3

你應該建議這個評論。這不能證明簡短的答案。 –

+1

但是這個問題仍然沒有得到答案。因爲這基本上就是答案。 – jaibatrik

+0

問題沒有解答。他們在SO上有很多可用的重複解決方案。你可以建議解決方案之一。 –