add permissions in android, add internet permission to app, android permissions list, android tutorial,  android permissions

How to add permissions to an app in android

In android app development, permissions are a key factor for a successful app development since they play a key role. Unlike other development languages, android does not assume that a certain role is needed and it includes it by default, what happens is that you have to add it manually so that android can actually use it. For example, the Google Maps application, and by default, we know that it needs access to your location, it does not assume rather it has to ask the input of the user to allow it use location and this is defined as a permission.

Permissions in the android studio are defined in the android manifest file. By default, the manifest file always contains the activities that have been created, for example, the main activity, login activity, and so on. It also defines the activity which will load first when the app is opened. For example, the code snippet below shows the default manifest file when I have home activity, main activity, and register activity.

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.example.kotlinexample">

 

    <application

        android:allowBackup="true"

        android:icon="@mipmap/ic_launcher"

        android:label="@string/app_name"

        android:roundIcon="@mipmap/ic_launcher_round"

        android:supportsRtl="true"

        android:theme="@style/Theme.KotlinExample">

        <activity android:name=".HomeActivity"></activity>

        <activity android:name=".RegisterActivity" />

        <activity android:name=".MainActivity">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

 

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

    </application>

 

</manifest>

Permissions in the manifest file are added above the application tag. The permissions are initialized using the uses-permission attribute as shown below

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

Examples of permissions

  1. Suppose we have an application that you want to either fetch data or send data to an online server, this is made possible when we add the internet permission to the app.

The internet permission is added as follows

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

Adding the above code snippet in the manifest will allow give the android app permission to either access or send data to an online server

  2. If you have an app that you want to write data to the memory of your device such as if you are storing data in an SQLite database, we must give the permission of writing data to the memory as shown below

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

     3.To read data stored in the device storage, we need to use the read data permission shown below

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

There are so many permissions provided by the android platform and it depends on the function you want to achieve in your application. The default script for loading permissions is like the one shown below

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

Whereby after the dot (.), permissions usually pops up and you scroll down to select the permission you want to add.

The manifest file after adding permissions will be as follows

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.example.kotlinexample">

 

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

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

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

    <application

        android:allowBackup="true"

        android:icon="@mipmap/ic_launcher"

        android:label="@string/app_name"

        android:roundIcon="@mipmap/ic_launcher_round"

        android:supportsRtl="true"

        android:theme="@style/Theme.KotlinExample">

        <activity android:name=".HomeActivity"></activity>

        <activity android:name=".RegisterActivity" />

        <activity android:name=".MainActivity">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

    </application>

</manifest>

 

In this article, we have discussed how to add permissions to an app in android and we have seen that android does not just decide to do anything without being granted permission to do so through the use of different permissions that are provided for in the android platform.

Please note that if you remove permission, the function requiring the use of that permission will not work.