Runtime permission in Android

In my closing instructional, We had practiced superior options of RxJava in Android. Listed here are the hyperlink main points RxJava in android part1 ^(, RxJava in android part2 ^( and MVP with RxJava ^(

Nowadays we were given one extra day to be informed one thing extra. Let’s make at the moment extra superior to be informed one thing new. On this article, we will be able to be informed why runtime permission and find out how to give permission at runtime in the applying. Previous we now have practiced that the person may also be observed the permission element at whilst putting in the app. However in marshmallow software model 6.0 it has modified. Now utility is probably not granted the permission whilst putting in the applying. It’s going to ask customers at runtime. Why that is required? 

Hi there! I discovered one superior android app for you it is identify PhonePe – India’s Fee App. PhonePe is a innovative option to make cell bills in India. Please do this. ^(

Within the earlier underneath the marshmallow variations just like the lollipop and different decrease model gadgets, Person used to be felt like obtrusive to look the permission main points whilst putting in that, They may well be pondering that why can I shared my confidential knowledge with out asking that permission. The applying must be requested me, good day if you wish to get admission to the ones then please grant me permission to get admission to. As an example, if another app needs to get get admission to the telephone touch then person really feel obtrusive to present get admission to the ones. That why it comes runtime permission. If the opposite utility needs to get admission to telephone touch of customers then its all rely at the person in the event that they granted the permission or now not. If the person has now not granted then different utility is probably not allowed to get admission to that knowledge.

One not unusual query of each and every developer that how android take care our outdated utility release on marshmallow software. So I might say don’t panic be comfy android take care that factor very neatly. In case your utility has constructed on targetsdkversion is not up to 23 then it must now not be crashed on Android M. It’s going to paintings wonderful with none factor. Runtime permission will handiest ask customers in the event you construct the app not off course SDK model 23 or upper. 

This truly sounds excellent for the customers to really feel self belief that my telephone is protected if I used to put in another utility with none factor. Android take care safety standpoint on the most sensible precedence. Superior:)

Ok, Let’s examine what are the ones permissions is granted whilst putting in the applying. Those permissions referred to as protection-level permission. It’s going to now not ask the person at runtime.


Nice. This permission is needed so as to add in Android manifest report then it really works wonderful with none crash. Now let’s test what are required to test the permission if my goal SDK model and bring together SDK model is 23 or upper.

A developer must practice three elementary strategies.
1. checkSelfPermission(Permission) – to test the permission is already granted or now not.
2. requestPermissions(String [] permissions, int requestCode) – if now not then request for permission
3. onRequestPermissionsResult(int premsRequestCode, String [] permissions, int [] grantResults) – to test the outcome whether or not permission is granted or now not.

Let’s examine one instance I’m construction an app which goals SDK model is 23 or upper. I would like location get admission to in one of my utility. To begin with, you want to grasp what are permission is needed for get admission to the Location. Ok, How do I ensure that? Let’s test in framework point what Gooogle has outlined for location get admission to?
After I glance this report ^( in framework module.
I discovered this permission is needed to get admission to the site.

 personal static ultimate Set ^(<String ^(>  ^( ^( = new ArraySet ^(<>();
109 ^( static

So mainly those two permission is needed to get admission to Location. Adequate, Let’s test whilst clicking on a button I wish to get admission to the site.

import android.Manifest;
import android.content material.DialogInterface;
import android.content;
import android.os.Construct;
import android.os.Package;
import android.fortify.annotation.Nullable;
import android.fortify.v4.content material.ContextCompat;
import android.widget.Button;
import android.widget.Toast;

import com.sunil.mvprxjavaapp.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

* Created by way of sunil on 08-04-2017.

public elegance RunTimePermissionTestActivity extends AppCompatActivity {

Button RuntimeButton;

secure void onCreate(@Nullable Package savedInstanceState)

public void RunTimeClick()

public static ultimate int MY_PERMISSIONS_REQUEST_LOCATION = 99;
personal void askLocationPermission() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

// Must we display a proof?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.ACCESS_FINE_LOCATION)) else

personal void tryToGetLocationValue()

public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
transfer (requestCode)

Upload this line in Android Manifest report.


Nice You probably did smartly. It does now not require to test permission for each ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION. Android report stated you’ll be able to permit handiest one permission is sufficient for get admission to however wish to upload each permissions in the android manifest report.

Screenshot_20170408-230129 Runtime permission in Android Android generic_300x250 Runtime permission in Android Android ^(

Screenshot_20170408-230153 Runtime permission in Android Android

Screenshot_20170408-230203 Runtime permission in Android Android

You’ll see about snaps, It’s going to ask for the person to permit or deny. If a person has denied press and once more he tries to get admission to location whilst clicking at the button it activates to the person to want permission get admission to to person location capability. Then this time activates presentations with test field by no means ask once more. If the person has checked this field it way person now not in permitting this permission and now not in the usage of location function anymore.

Thank you for studying this submit.

234x60B Runtime permission in Android Android