-5

請幫助我獲得權限「WRITE_EXTERNAL_STORAGE」和「WRITE_SETTINGS」的請求代碼。 也讓我知道請求代碼的來源。請求代碼在Android的權限

+1

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

+0

您可以定義自己的請求代碼。 – Prexx

+0

怎麼樣?你可以給我一個例子 – Ankith

回答

0

一個簡單的演示:

// Here, thisActivity is the current activity 
if (ContextCompat.checkSelfPermission(thisActivity, 
       Manifest.permission.WRITE_EXTERNAL_STORAGE) 
     != PackageManager.PERMISSION_GRANTED) { 

     ActivityCompat.requestPermissions(thisActivity, 
       new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 
       YourRequestCode); 
} 

您可以設置YourRequestCode任何值,如1

+0

我錯了requestcode concept.thanks我這個代碼做了我的問題。感謝所有.. – Ankith

+0

如果上面的代碼適合你,你應該將其標記爲接受。 – cole

0
public void getPermission() { 
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { 
     ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_CONSTANT); 
    } else { 
     uiBind(); 
    } 
} 

@Override 
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 
    switch (requestCode) { 
     case PERMISSION_CONSTANT: 

      if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 
       getPermission(); 
      } 
      break; 
    } 
} 
    1.
+0

請添加一些解釋。 – BlackBeard