How to Request a Run Time Permission – Android Studio Tutorial



In this video we will learn, how to request a dangerous READ_EXTERNAL_STORAGE permission at run time, which is necessary since Android 6.0 (Marshmallow), whereas before this permission would be granted at the installation process. For this we will use the checkSelfPermission and requestPermissions methods and show a rationale to the user at the appropriate time with the shouldShowRequestPermissionRationale method.

Source code:

____________________
❗ Subscribe to the channel:

⏯ Watch more tutorials:

㊙ Help translating the videos:

💚 Support the content:

💬 Join the Discord chat:

🎧 Audiobooks and podcasts for programmers:

👶 How to get started with Android development:

📣 Follow Coding in Flow on social media:

Facebook:

Instagram:

Twitter:

Blog:

Nguồn: https://rmacct.org/

Xem thêm bài viết khác: https://rmacct.org/cong-nghe/

  • I love your tutorials! You show and explain everything in a clear and easy to understand manner. Your tutorials have helped me so many times. Thanks!

    Daniel Biddlecom July 10, 2020 11:18 pm Reply
  • Legendddddd ❤️. I have followed so many of your videos and they all workkkk ❤️❤️❤️

    Kalsoom Asghar July 10, 2020 11:18 pm Reply
  • Bhai . Mera nhi log in nhi ho rha kuch idea Dona . Plzzz

    Saroj Kumarb July 10, 2020 11:18 pm Reply
  • private void isPermissionGranted(){

    if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE)==PackageManager.PERMISSION_GRANTED){

    Toast.makeText(getContext(), "PERMISSION GRANTED", Toast.LENGTH_SHORT).show();

    } else {

    requestStoragePermission();

    }

    }

    void requestStoragePermission(){

    if(shouldShowRequestPermissionRationale(Manifest.permission.READ_EXTERNAL_STORAGE)){

    new AlertDialog.Builder(getContext())

    .setTitle("Permission needed")

    .setMessage("This permission is needed because of")

    .setPositiveButton("OK", new DialogInterface.OnClickListener() {

    @Override

    public void onClick(DialogInterface dialogInterface, int i) {

    requestPermissions(new String[] {Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSIONS_CODE);

    }

    })

    .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

    @Override

    public void onClick(DialogInterface dialogInterface, int i) {

    dialogInterface.dismiss();

    }

    }).create().show();

    } else {

    requestPermissions(new String[] {Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSIONS_CODE);

    }

    }

    Aleksandr Chashchin July 10, 2020 11:18 pm Reply
  • Can I show alert dialog here,after user click on don't ask again and deny also, share the code please, it would be very helpful to me

    bankuru vasavilatha July 10, 2020 11:18 pm Reply
  • Sir, will my audio record work with permission granted only I'm manifest file?

    Pühvo Puro July 10, 2020 11:18 pm Reply
  • Is this runtime permission necesery if you want to put your app on google play store?

    Bojan Dosen July 10, 2020 11:18 pm Reply
  • Pls don't stop your awesome work….! You are the best and beast :)))

    Andi Hoxha July 10, 2020 11:18 pm Reply
  • IT WAS SO PRECISE. THANK YOU SO MUCH♥ You are a hope to we Juniors

    Abhishek Dere July 10, 2020 11:18 pm Reply
  • Sir.. android.permission. is not poping out in suggestion box

    Pühvo Puro July 10, 2020 11:18 pm Reply
  • Thanks this video helped me a lot. Do keep up the good work .

    Jowel Tisso July 10, 2020 11:18 pm Reply
  • Thanks A lot Very Helpful. What if i want to request Permissions when the user launches the application?

    Mohamed Zaifri July 10, 2020 11:18 pm Reply
  • hi bro can you make video how to make app run always in background

    TOP Games Android July 10, 2020 11:18 pm Reply
  • Thanks, guy! Its really work! I miss 3 days for solve this problem, but you video had helped me! Like!

    Tvybert July 10, 2020 11:18 pm Reply
  • You've saved my life not only once!!!

    Vu Anh Minh Le July 10, 2020 11:18 pm Reply
  • Works on Android studio but not in real device ?
    And can you please tell why am i not getting JSON data from web in my real device but I get it on Android studio?

    Nishant J July 10, 2020 11:18 pm Reply
  • /storage/emulated/0/Download/2020-03-30 19:32:03.pdf: open failed: EACCES (Permission denied)
    What this error means and how to solve it.

    Darius Gavėnia July 10, 2020 11:18 pm Reply
  • Thank you thank you!

    Anna Farman July 10, 2020 11:18 pm Reply
  • Web view geolocation permission dialog not showing. Please write your code

    Abu Hamza July 10, 2020 11:18 pm Reply
  • This guy is a living legend

    Anonymous July 10, 2020 11:18 pm Reply
  • Nice…..

    7days July 10, 2020 11:18 pm Reply
  • Hello Sir,
    I can't share videos ,photos
    Version >= Nougat

    Lipom Daimary July 10, 2020 11:18 pm Reply
  • hi,how can i access these photos?

    osoos osososo July 10, 2020 11:18 pm Reply
  • Would you please do a video on how to delete a sent SMS from inside your app, also how to grant permissions for apps that have multiple activities which require permissions. Thanks in advance….great video!

    Sophie333C July 10, 2020 11:18 pm Reply
  • is it possible to achieve this with "extends Activity" instead of "extends AppCompatActivity"?

    Taironchai Chang Duarte July 10, 2020 11:18 pm Reply
  • Brilliance, respect .

    Alex B July 10, 2020 11:18 pm Reply

Leave a Reply

Your email address will not be published. Required fields are marked *