RhinoCan
Well-Known Member
I've been side-tracked on permissions for a couple of days now, trying to make my app behave the way the tutorials and videos say it should behave. I'm not having a lot of luck though.
I'm trying to write a little experimental app that determines a unique ID from the device it is running on. (I know this is a very dubious quest having stumbled on a StackOverflow discussion so my real app will NOT try to do this. But for now, I still want to finish my experimental app PURELY to learn the proper way of asking and getting permission and getting a unique ID serves that purpose as well as anything.
I've got a big problem in my experimental app. First, the line that says:
ALWAYS returns false, regardless of whether I have given permission in the manifest or not. My understanding, based on the information I've seen in tutorials and videos is that checkSelfPermission() should return true if the permission is granted in the manifest and false otherwise. Why is my app behaving differently?
Here's my permission:
I'm 99% certain that syntax is right and that Android Studio would flag it anyway if it was wrong in some respect. This permission is also in the right place in the manifest: after the initial <manifest> tag but before the <application> tag.
Every video and tutorial tells you to put this permission in the manifest so I have done so but I'm really not clear on something. Does <uses-permission> really mean that the app has permission in advance and doesn't need to acquire permission when it is running? That would seem to be completely opposite to the Android 6.0 model (as I understand it) which says you should not ask for permission at install time but only at run time (at least for a "dangerous" permission like READ_PHONE_STATE). How is <uses-permission> making developers defer getting permission? Or is <uses-permission> simply information used by Android so that it knows in advance what permissions will be requested of the user at runtime? Also, do I need to create <uses-permission> entries for "safe" privileges too or does Android figure out for itself what it needs to get at install time by analyzing my code?
One other thing isn't clear to me either. This line:
ALWAYS returns false. How do I make it return true? It's going to be hard to see if the code for showing the rationale works unless I can make the if return a true ;-)
I'm trying to write a little experimental app that determines a unique ID from the device it is running on. (I know this is a very dubious quest having stumbled on a StackOverflow discussion so my real app will NOT try to do this. But for now, I still want to finish my experimental app PURELY to learn the proper way of asking and getting permission and getting a unique ID serves that purpose as well as anything.
I've got a big problem in my experimental app. First, the line that says:
Java:
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE)
== PackageManager.PERMISSION_GRANTED) {
Here's my permission:
Code:
<uses-permission android:name="READ_PHONE_STATE"/>
I'm 99% certain that syntax is right and that Android Studio would flag it anyway if it was wrong in some respect. This permission is also in the right place in the manifest: after the initial <manifest> tag but before the <application> tag.
Every video and tutorial tells you to put this permission in the manifest so I have done so but I'm really not clear on something. Does <uses-permission> really mean that the app has permission in advance and doesn't need to acquire permission when it is running? That would seem to be completely opposite to the Android 6.0 model (as I understand it) which says you should not ask for permission at install time but only at run time (at least for a "dangerous" permission like READ_PHONE_STATE). How is <uses-permission> making developers defer getting permission? Or is <uses-permission> simply information used by Android so that it knows in advance what permissions will be requested of the user at runtime? Also, do I need to create <uses-permission> entries for "safe" privileges too or does Android figure out for itself what it needs to get at install time by analyzing my code?
One other thing isn't clear to me either. This line:
Java:
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.READ_PHONE_STATE)) {