系统无需用户操作即可授予权限

时间:2015-12-30 11:08:31

标签: android android-permissions android-6.0-marshmallow runtime-permissions

我面临一个奇怪的问题。我遵循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);
    }

The Manifest:

<uses-permission-sdk-23 android:name="android.permission.INTERNET"/>

结果如下:

enter image description here

并没有要求许可:

enter image description here

任何建议?

1 个答案:

答案 0 :(得分:5)

互联网是“正常许可”,它由系统授予而不询问用户。请参阅documentation

中的详情

系统仅会询问用户dangerous permissions