2016-12-22 48 views
0

我們在合適的標籤之間寫了所有權限代碼。但是當我安裝程序時,並沒有詢問權限。 我的錯在哪裏?權限不起作用,當我安裝程序時不會被詢問

這是我的manifest.xml文件

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.berker.notkayit"> 

<uses-sdk 
android:minSdkVersion="21" 
android:targetSdkVersion="24" /> 


    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 



    <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"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 
+0

可能的[Android棉花糖請求權限?]的重複?(http://stackoverflow.com/questions/33666071/android-marshmallow-request-permission) –

回答

0

是U測試中的棉花糖及以上設備是指在安裝過程中不會請求許可,但應用程序會在運行時允許具有u增加了運行許可權代碼

0

從棉花糖起,我們必須以編程方式添加運行時的權限。

閱讀本文件

https://developer.android.com/training/permissions/requesting.html

Breifly我提供瞭如何做

  1. 檢查是否准許對不

int permissionCheck = ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.WRITE_CALENDAR);

  • 然後處理其
  • @ 
     
    Override 
     
    public void onRequestPermissionsResult(int requestCode, 
     
        String permissions[], int[] grantResults) { 
     
        switch (requestCode) { 
     
        case MY_PERMISSIONS_REQUEST_READ_CONTACTS: 
     
         { 
     
         // If request is cancelled, the result arrays are empty. 
     
         if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 
     
    
     
          // permission was granted, yay! Do the 
     
          // contacts-related task you need to do. 
     
    
     
         } else { 
     
    
     
          // permission denied, boo! Disable the 
     
          // functionality that depends on this permission. 
     
         } 
     
         return; 
     
         } 
     
    
     
         // other 'case' lines to check for other 
     
         // permissions this app might request 
     
        } 
     
    }

    這是你必須在6.0至處理和上述情況,如果您的裝置是通過以下方式6.0,清單會爲你做

    相關問題