How to add manifest permission to an application?

后端 未结 9 1301
甜味超标
甜味超标 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

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

    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.

    <uses-permission android:name="android.permission.CAMERA"/>
    

    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'
    }
    
    0 讨论(0)
  • 2020-11-22 16:44

    Copy the following line to your application manifest file and paste before the <application> tag.

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

    Placing the permission below the <application/> tag will work, but will give you warning. So take care to place it before the <application/> tag declaration.

    0 讨论(0)
  • 2020-11-22 16:50

    That may be also interesting in context of adding INTERNET permission to your application:

    Google has also given each app Internet access, effectively removing the Internet access permission. Oh, sure, Android developers still have to declare they want Internet access when putting together the app. But users can no longer see the Internet access permission when installing an app and current apps that don’t have Internet access can now gain Internet access with an automatic update without prompting you.

    Source: http://www.howtogeek.com/190863/androids-app-permissions-were-just-simplified-now-theyre-much-less-secure/

    Bottom line is that you still have to add INTERNET permission in manifest file but application will be updated on user's devices without asking them for new permission.

    0 讨论(0)
提交回复
热议问题