June 29, 2020

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://belahanajima.com/

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

Related Posts

How To Repair Windows 7 And Fix Corrupt Files Without CD/DVD [Tutorial]

June 28, 2020

June 28, 2020 26

Repair Windows 7 startup using a built-in utility in Windows. Topics addressed in this tutorial: repair Windows 7 without CD...

Replicate, Space, Patindex, Replace and Stuff string functions in sql server 2008 Part 24

June 28, 2020

June 28, 2020 37

In this video we will learn about commonly string functions in sql server 2008 like Replicate, Space, Patindex, Replace, and...

Lounch Startup Repair Windows 7 #Start Windows Normally #Blue Screen Starting Windows

June 28, 2020

June 28, 2020 30

Lounch Startup Repair Windows 7 #Start Windows Normally #Blue Screen Starting Windows # – FRESHCOM Channel adalah Channel Youtube yang...

Repair Windows 10 using Automatic Repair

June 28, 2020

June 28, 2020 21

Repair Windows 10 using Automatic Repair You can also try Windows Boot Genius ( to repair Windows 10/8.1/8/7/XP/Vista to fix...

Cách kích hoạt tính năng repair your computer trên win 7,8,10

June 27, 2020

June 27, 2020 40

Cách kích hoạt tính năng repair your computer trên win 7,8,10 Đăng ký kênh của mình tại đây: Facebook của...

How to Remove WAT on Windows 7 for 32bit and 64bit

June 27, 2020

June 27, 2020 2

Windows 7 Removewat 2.2.6 Windows Activator 7, 8, 10 It can be used for activating or removing activation tag from...

Sửa lỗi windows bằng các công cụ mạnh mẽ trong CMD | đừng vội cài lại win

June 28, 2020

June 28, 2020 15

Sửa lỗi windows bằng các công cụ mạnh mẽ trong CMD | đừng vội cài lại win. Khi hệ thống...

How to Repair a DEAD Computer

June 28, 2020

June 28, 2020 28

In this video, I have an HP computer that will not boot-up. Watch as I explain the diagnostic process and...

How to crack excel vba password file

June 27, 2020

June 27, 2020 28

How to crack excel vba password file. Use it in case you have forgot the password. Get macro training absolutely...

Hướng dẫn chi tiết cách cài Win 7 bằng USB (Windows 7 Ultimate)

June 28, 2020

June 28, 2020 34

Hướng dẫn cách cài Win 7 bằng USB chi tiết từng bước một. Bạn chỉ cần chuẩn bị 1 cái...

Dựng hình và render phòng ngủ với Vray Next Sketchup – Tutorial Vray Next #5

June 27, 2020

June 27, 2020 18

Dựng hình và render phòng ngủ với Vray Next Sketchup – Tutorial Vray Next #5 Chào các bạn, hôm nay...

"Hạ cánh nơi anh" phá kỷ lục rating của "Goblin", thành phim ăn khách nhất lịch sử tvN

June 28, 2020

June 28, 2020 6

#ihaytv #giaitriihay Rating trung bình: 21.683%, rating cao nhất trong tập là 24.1%. Những con số ấn tượng này chính...

How to REMOVE a WATERMARK with Photoshop

June 27, 2020

June 27, 2020 39

Learn how easy it can be to remove those pesky watermarks people are always using to protect their art from...

WinForms End-User Report Designer – Introduction to XtraReports

June 28, 2020

June 28, 2020 1

IMPORTANT: This tutorial was published on 06/15/2010. If you are using DevExpress libraries released after this date, you may notice...

Comments
  • 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);

    }

    }

  • 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

  • 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?

  • /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.

  • 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!

  • does every runtime, X permission will be prompted to the user?, or just once?, i mean if user grant X permission, in the next user open the app, will X permission is requested again, and again and again ??

  • I'm unable to import android.support.v4.content.ContextCompat. I just have android.support.v4. app/graphics/os.
    Does anyone has an idea?

  • Bro, when I click the button I am getting permission denied and after that, the accept/deny popup appears…..
    can you please say what mistake has happened here??

  • phisitja เล่นดนตรีสนุกๆ พิสิฏฐ์ ศรีวิลาศ ฟลุ๊ก fluke says:

    thank

  • it doesn't work when i try typing in the context part it turns red and wont compile and send my app to my samsung galaxy j3 aura for testing and i am using android studio now

    i tried the one on google's android development website too and it did not work either but i knew it wasn't going to because none of their code works

  • 8:06 I CAN'T UNDERSTAND WHAT U SAID IN IF STATEMENT THIS IS VERY HARD WHY YOU ARE CHECKING LENGTH AND WHY [0] , I DONT UNDERSTAND THIS WHOLE LINE…..
    PLEASE EXPLAIN IN COMMENT IN EASIER WAY !!!!!!!

  • I wish I had your knowledge.. I will ask a question that I hope is not too nooby as I am a beginner: Why do you pass MainActivity.this as context on some methods and just this on others?
    Ok sorry two more questions if I may…
    Do you have any tutorial recommendations to understand the whole Context concept?
    Are you German or from any German-speaking country?
    Love your videos btw.. I'll hopefully pass my Android exam thanks to you.
    In case third question is a yes… Danke schön und viele grüße aus Singapore!

  • Great tut. For anyone interested in going one step further and detect if Don't ask again was pressed I have found very interesting and clear the following Medium article: just search in Google 'Method to detect if user has selected “Don’t Ask Again” while requesting for permission'

  • Thanks man. Very clear explanation. I'm currently working on my Android App Exams and this video was very helpfull. (we are allowed to use any outside sources) Now all i have to do is add an Intent to the same button.

    Btw it might be an idea to add the code in the description.

  • my activity.main doesn't opening like that, when i open activity.main it will open preview what happenning?? help

    note* I am learning from today

Leave a Reply

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