How to add manifest permission to an application?

后端 未结 9 1299
甜味超标
甜味超标 2020-11-22 15:46

I am trying to access HTTP link using HttpURLConnection in Android to download a file, but I am getting this warning in LogCat:

9条回答
  •  孤独总比滥情好
    2020-11-22 16:42

    I am late but i want to complete the answer.

    An permission is added in manifest.xml like

    
    

    This is enough for standard permissions where no permission is prompted to the user. However, it is not enough to add permission only to manifest if it is a dangerous permission. See android doc. Like Camera, Storage permissions.

    
    

    You will need to ask permission from user. I use RxPermission library that is widely used library for asking permission. Because it is long code which we have to write to ask permission.

    RxPermissions rxPermissions = new RxPermissions(this); // where this is an Activity instance // Must be done during an initialization phase like onCreate
    rxPermissions
        .request(Manifest.permission.CAMERA)
        .subscribe(granted -> {
            if (granted) { // Always true pre-M
               // I can control the camera now
            } else {
               // Oups permission denied
            }
        });
    

    Add this library to your app

    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }
    
    dependencies {
        implementation 'com.github.tbruyelle:rxpermissions:0.10.1'
        implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.1'
    }
    

提交回复
热议问题