Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] java – permission denial in android studio

Posted on November 14, 2022

Solution 1 :

Add permission to the manifest.xml file:


enter image description here

Problem :

I want to create an android application which view phone contact in application and I wrote this code in my activity

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, 1);
            requestPermissions(new String[]{Manifest.permission.WRITE_CONTACTS}, 1);
            requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE}, 1);
        }
Uri u = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
Cursor curs = getContentResolver().query(u, null, null, null, null);
btn_some.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showContacts();
            }
        });

this code works fine with emulator but when I tried it on my phone it has stopped
logcat message is

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.MyApplication/com.example.MyApplication.MainActivity}: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{5b66da3 28379:com.example.MyApplication/u0a264} (pid=28379, uid=10264) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS

and this is my Mainfest

<uses-permission android_name="android.permission.READ_PHONE_STATE"/>
<uses-permission android_name="android.permission.READ_CONTACTS"/>
<uses-permission android_name="android.permission.WRITE_CONTACTS"/>

How can I run this application on my phone ?

Comments

Comment posted by Mohamed Hoosam

it’s already exist in it

Comment posted by developer.android.com/training/contacts-provider/…

Please take a deep look to the

Comment posted by Mohamed Hoosam

okay now it’s worked but when I open application for first time it stopped again and then I get permission message on my phone when I accept all permission application run correctly so can I solve that ?

Comment posted by Rashad Nasirli

It is worked after accepting permissions, and what did it say when stops?

Comment posted by Mohamed Hoosam

Thanks a lot I resolved this issue by override onActivityResult method and application run correctly

READ  [ANSWERED] kotlin - Double fragment instance when it comes from background
Powered by Inline Related Posts

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress