Permission not asked - android

I'd like to know why my permission are not asked when I'm launching my app, here's my manifest permissions :
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
And when I go through the param of my phone, I only have the "position" permission (and it's disabled).

If by permission not asked you mean that the user isn't being prompted to allow internet permission then that is normal. Internet is in the normal permissions list so it is auto granted. For more information about normal permissions take a look at: https://developer.android.com/guide/topics/permissions/normal-permissions.html
Also, adding permissions is a two step process; once you have declared the permission you need in your manifest, you will also have to do some setup in your java file. Take a look at https://developer.android.com/training/permissions/requesting
Additionally, if you are looking for easier ways to deal with permissions then there are libraries out there for that too such as RxPermissions: https://github.com/tbruyelle/RxPermissions
Hopefully this helps!

You should ask for a Runtime Permission
Please see the documentation:
Request App Permissions

If you are targeting SDK 26+, then you need to check for permissions in code like this:
if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.ACCESS_FINE_LOCATION)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(thisActivity,
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
MY_PERMISSIONS_ACCESS_FINE_LOCATION)
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
} else {
// Permission has already been granted - or running on old Android
}
It is described in Request App Permissions

for marshmallow(API 23) and above you should get permission for location, phone states and other dangerous permissions not only in your manifest but in your code (Run Time Permission).for other permissions, manifest is enough.
see this video
also you can find your solution in this Q&A

Related

Kotlin: App not asking user for permissions

I am creating an Android application that reads a user's SMS messages. I first check whether the user has granted permission for me to read the SMS messages with the if conditional. I have verified that my test phone has not granted access to the app to read the SMS messages, as the print statement is executed. However, the requestPermissions method is not triggered (there is no popup asking to grant permission to read the SMS messages). I suspect I might be using the wrong permission code or the wrong method to begin with. I have included the following permission in my Manifest.xml file:
<uses-permission android:name="android.permission.SEND_SMS"/>
Below is my Kotlin code:
// See if the user has not granted permission to read his or her text messages
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_SMS) == PackageManager.PERMISSION_DENIED) {
// Request the user to grant permission to read SMS messages
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_SMS), 2);
System.out.println("Permission Denied")
}
In AndroidManifest.xml add READ_SMS
permission.
Use
<uses-permission android:name="android.permission.READ_SMS"/>
Instead of
<uses-permission android:name="android.permission.SEND_SMS"/>
As it is mentioned in comments, You have declared SEND_SMS permission in Manifest.xml file and requesting READ_SMS permission dynamically(runtime).
Also it is not recommended to use this permission unless app acts as default messaging app. Please go through documentation Manifest.permission.READ_SMS which states following
This is a hard restricted permission which cannot be held by an app
until the installer on record whitelists the permission. For more
details see
PackageInstaller.SessionParams.setWhitelistedRestrictedPermissions(Set)

Why do I have to add the Permission into the Manifest although I do request them on start

On startup I ask for permission with a Codeblock like this:
if (ContextCompat.checkSelfPermission(getContext(),
Manifest.permission.WRITE_SETTINGS)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
Manifest.permission.WRITE_SETTINGS)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
intent.setData(Uri.parse("package:" + getActivity().getPackageName()));
startActivity(intent);
}
}
The Request prompts but im not able to grant the permission until I add this to my Manifest:
<uses-permission android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />
Why do I have to add the uses-permission although it's only for system apps(at least android studio tells me that) and i request the needed permission on start up.
Becouse Google needs to know what permissions your app uses for multiple purposes. One of them is to show the app permissions on your app's store listing.
Scanning all your codebase just to figure out what permissions your app is using is not really the best way to deal with it, is it?

Android 6 (23) - no permission requested

I stucked on new permission model in the Android 6.
I defined following permissions in the manifest:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application...
But if i launched the app in the emulator and opened the app detail i saw the following :
It says that app does not require any permission.
How can i solve it please?
Many thanks for any advice.
It says that app does not require any permission.
That is correct. That portion of your app's page lists dangerous permissions. None of yours have a protectionLevel of dangerous.
How can i solve it please?
There is nothing wrong, and so there is nothing to solve.
Until Android 6.0, There are some permissions that will be automatically granted at install time and will not be able to revoke. We call it Normal Permission (PROTECTION_NORMAL). Here is the full list of them:
android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_NOTIFICATION_POLICY
android.permission.ACCESS_WIFI_STATE
android.permission.ACCESS_WIMAX_STATE
android.permission.BLUETOOTH
android.permission.BLUETOOTH_ADMIN
android.permission.BROADCAST_STICKY
android.permission.CHANGE_NETWORK_STATE
android.permission.CHANGE_WIFI_MULTICAST_STATE
android.permission.CHANGE_WIFI_STATE
android.permission.CHANGE_WIMAX_STATE
android.permission.DISABLE_KEYGUARD
android.permission.EXPAND_STATUS_BAR
android.permission.FLASHLIGHT
android.permission.GET_ACCOUNTS
android.permission.GET_PACKAGE_SIZE
android.permission.INTERNET
android.permission.KILL_BACKGROUND_PROCESSES
android.permission.MODIFY_AUDIO_SETTINGS
android.permission.NFC
android.permission.READ_SYNC_SETTINGS
android.permission.READ_SYNC_STATS
android.permission.RECEIVE_BOOT_COMPLETED
android.permission.REORDER_TASKS
android.permission.REQUEST_INSTALL_PACKAGES
android.permission.SET_TIME_ZONE
android.permission.SET_WALLPAPER
android.permission.SET_WALLPAPER_HINTS
android.permission.SUBSCRIBED_FEEDS_READ
android.permission.TRANSMIT_IR
android.permission.USE_FINGERPRINT
android.permission.VIBRATE
android.permission.WAKE_LOCK
android.permission.WRITE_SYNC_SETTINGS
com.android.alarm.permission.SET_ALARM
com.android.launcher.permission.INSTALL_SHORTCUT
com.android.launcher.permission.UNINSTALL_SHORTCUT
Just simply declare those permissions in AndroidManifest.xml and it will work just fine. No need to check for the permission listed above since it couldn't be revoked.
as #Saini said, Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app.
But if you choose targetSdkVersion lower than 23, your application will be treated like before and will ask user to grant permission to the app when they want to install application. you could read more from here
Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. This approach streamlines the app install process, since the user does not need to grant permissions when they install or update the app. It also gives the user more control over the app's functionality; for example, a user could choose to give a camera app access to the camera but not to the device location. The user can revoke the permissions at any time, by going to the app's Settings screen.
For more info: https://developer.android.com/training/permissions/requesting.html
https://developer.android.com/training/permissions/declaring.html
https://developer.android.com/training/permissions/best-practices.html
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.READ_CONTACTS)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.READ_CONTACTS},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
In addition to https://stackoverflow.com/a/42697645/984471
Here is the protection_normal permissions link:
https://developer.android.com/guide/topics/permissions/overview#normal_permissions
And the comparison between old and new, normals

Android not requiring permissions - Marshmallow 6.0.1 Unity

I'm building a Cardboard app and testing it on a Nexus 6P.
The problem I have is that when I install the app, it doesn't ask for any permissions.
In my manifest I have this:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Then if I want to download some file from the internet in my app, it doesn't work. It doesn't even create the com. folder.
I have to go manually to the app info and check the storage permission.
It's weird because when building the app for GearVR and testing it on a Note 4, it asks for permission (in the Note 4 I use the sd card, in Nexus 6P the internal)
Why is this happening?
Thank you.
For Android 6+ you need to request permissions at runtime, not startup. This is especially the case if you are considering your app for Google Play featuring,
In short, you need to specify the permission in tour manifest, and also include the following in your application tag
<meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="true" />
Then, request the permission(s) at runtime via Android.
There is a great little plugin for this at https://www.assetstore.unity3d.com/#!/content/62735
Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. Thats a reason why you didn't have request dialog.
If you need to request permission you need to show request rationale and handle user iteration result.
From docs :
Request permission :
if (ContextCompat.checkSelfPermission(thisActivity,Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.READ_CONTACTS)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.READ_CONTACTS},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
Handle User Choosed Option
In ActivityCompat :
#Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_READ_CONTACTS: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay! Do the
// contacts-related task you need to do.
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
}
Starting with Android 6.0 (Marshmallow) apps no longer get all permissions on install like they used to. You now have to request the permissions at runtime (which the user can decline) and have to be able to handle the permission getting revoked any time after it has been granted.
If you want to use the old behavior for now, I believe you should be able to set your target API level to 22.
Read more here: http://developer.android.com/training/permissions/requesting.html
for a quick fix, you can target android 5 (api level 22 instead of 23) and the permissions will keep using the old behavior.
note, if you publish an app targeting android 6 (level 23) api, you can't deprecate the target api level in an update.
https://developer.android.com/training/permissions/requesting.html

Android Program request permissions

I am trying to use GPS in android but it gives me this error:
I put in manifest these permission
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
can anyone help me please
As the hint suggests : The user may deny permission. In that case this call will throw error...
Right now, android asks for the user to accept all the permissions an app asks for in the manifest on installation. In the upcoming M release, android will switch over to the iOS style of permissions with an "on needed" basis.
Call this method to see if permission is granted or not. If not, you need to handle that situation.
context.checkCallingPermission(permission)
Declaring permission in manifest only means that you are requesting permission. In new releases it will not guarantee that user will give you that permission.
In older releases the user has to accept all or reject all permissions
This is not an error actually but a heads-up by the Lint and which may cause an issue!
Hope you are aware about the new permission model is introduced in Android 6.0 (Marshmallow), through which user may not permit to use GPS or Network or anything else and so it may cause an issue in your application!
Now, as per the lint analysis, so before implementing particular functionality, you should check whether permission for the same is available or not!
Since SDK 23, you should/need to check the permission using checkSelfPermission
http://developer.android.com/reference/android/support/v4/content/ContextCompat.html
for example
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
This condition checks user allowed to access the permission to read the location
if(checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)== PackageManager.PERMISSION_GRANTED||checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER,meter,mill,new locationlist(this));
}

Categories

Resources