1
我正面臨一個奇怪的問題。我遵循this教程,以便在運行時爲我構建的應用程序請求權限。問題是,即使我檢查設備是否使用Android M,並且我在運行時請求權限,但它不顯示對話框。系統通過無用戶操作授予許可
的代碼:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_configuration);
spinner = (Spinner)findViewById(R.id.database_selection_spinner);
button = (Button)findViewById(R.id.proceedBtn);
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(ConfigurationActivity.this, Manifest.permission.INTERNET) == PackageManager.PERMISSION_GRANTED){
accessWebService();
}else {
if (shouldShowRequestPermissionRationale(Manifest.permission.INTERNET)){
StringGenerator.showToast(ConfigurationActivity.this, "Internet Permission needs to be granted");
}
requestPermissions(new String[]{Manifest.permission.INTERNET}, AppConstants.PERMISSION_REQ_CODE);
}
}else {
accessWebService();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == AppConstants.PERMISSION_REQ_CODE){
if (grantResults[0] == PackageManager.PERMISSION_GRANTED){
accessWebService();
}else {
StringGenerator.showToast(ConfigurationActivity.this, "LOL");
}
}else {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
的accessWebService:
private void accessWebService(){
FetchDataTask task = new FetchDataTask();
task.execute(AppConstants.DATABASE_INFO_URL);
}
所述清單:
<uses-permission-sdk-23 android:name="android.permission.INTERNET"/>
下面是結果:
,也沒有請求的權限:
有什麼建議?
感謝您的回答......我現在覺得很愚蠢 –