Can't use android.permission.WRITE_SETTINGS in android manifest. im trying to turn on airplane mode by programatticaly and I can't add this permission in manifest.
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
The Android docs says:
Note: If the app targets API level 23 or higher, the app user must explicitly grant this permission to the app through a permission management screen. The app requests the user's approval by sending an intent with action ACTION_MANAGE_WRITE_SETTINGS. The app can check whether it has this authorization by calling Settings.System.canWrite().
So you have to request the user's approval explicitly by sending an intent with action ACTION_MANAGE_WRITE_SETTINGS.
What is the error message that you are getting? Is the app crashing when you try to open it or set the airplane settings? If you are targetting >API 23, you need to explicitly ask for permissions during runtime, this is a change from earlier versions when the permission was granted once at install time.
This link talks abou this:
https://developer.android.com/reference/android/Manifest.permission.html#WRITE_SETTINGS
Related
In later versions of Android (like 8.0.0), can we still declare normal level permissions in the manifest, like INTERNET permission and expect it to be granted at installation time?
<uses-permission android:name="android.permission.INTERNET" />
or do we need to explicitly request them through the code?
If the second, do we need to ask for it on every single activity?
can we still declare normal level permissions in the manifest, like INTERNET permission and expect it to be granted at installation time?
Yes. Only dangerous ones need to be requested at runtime.
Yes, you can declare normal level permissions in the manifest. But in 6.0 and above you have to check that permission is granted or not by user at runtime.
Instead of the interactive/runtime permissions, how can I set the permissions at install OR sticky permission so that this doesnt come up everytime I run the app.
The two permissions are LOCATION & CAMERA.
In general you request permissions in your manifest file so that the user can agree when he installs the application.
However, there has been a change recently in Android 6.0 which requires that the user is asked at runtime if the permission is dangerous. The android.permission.CAMERA permission is on of those dangerous permissions. As noted by mmBs you could set your target API level to less than Android 6.0 (e.g. 21 = 5.0) to achieve backwards compatible behaviour. But I would recommend to always update the target API level to the latest platform.
Nevertheless, you can take photos by capturing the photo using an intent (https://developer.android.com/training/camera/photobasics.html). That way your app doesn't need the CAMERA permission (the other app invoked by your intent does, but not yours).
From app I gave the required permission for my app. While my app is running, I went to system settings page and revoked the permission. The app is crashing. Will we be able to handle this?.
Android 6.0 (Marshmallow, API 23) switched from an install-time permission model to a runtime permission model. Now instead of the user granting all permissions at runtime, you the developer are responsible for requesting permissions at runtime and responding appropriately.
You should begin by reading the Requesting Permissions at Run Time documentation. So that you can properly request permissions on devices running Marshmallow.
To prevent your app from crashing, you need to call ContextCompat.checkSelfPermission() to see if you have a permission before attempting to call a method that requires a permission. However, this is only half the equation since you still need to request the permission if you don't already have it.
I'm applying Android 6.0 runtime permissions into an app which listens to carrier data connection state changes. I first tried to just remove the READ_PHONE_STATE from the manifest to check where the app requires the permission. To my surprise the app didn't crash at all.
After this I've tried the same installation on two pre 6.0 devices which did actually crash on it. To me it seems like Android 6.0 does no longer require the permission. Is there any way to confirm this?
The line below is the one on which the pre 6.0 devices crashes:
tm(TelephonyManager).listen(this, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
Is there any way to confirm this?
Yes, this commit removes the request of READ_PHONE_STATE when register the event type LISTEN_CALL_STATE, LISTEN_DATA_ACTIVITY and LISTEN_DATA_CONNECTION_STATE:
Do not enforce PHONE_STATE_PERMISSION to register listener PHONE_STATE_PERMISSION should not be required to register to the following event types:
- PhoneStateListener.LISTEN_CALL_STATE
- PhoneStateListener.LISTEN_DATA_ACTIVITY
- PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
In case of LISTEN_CALL_STATE, an empty string should be passed instead of incomingNumber, when caller has no PHONE_STATE_PERMISSION.
Bug: 21588537 Change-Id: I5b6d0308924f7e4cd13a983b8e0c9b3a5bbb119b
The documentation on developer.android.com was updated and correctly shows that the permission are not required.
If your code doesn't need the permission READ_PHONE_STATE for other reason apart from LISTEN_DATA_CONNECTION_STATE you can change your AndroidManifest.xml adding maxSdkVersion to the uses-permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE" android:maxSdkVersion="22" />
There is no special permission listed for PhoneStateListener.LISTEN_DATA_CONNECTION_STATE in the official android documentation.
http://developer.android.com/reference/android/telephony/PhoneStateListener.html#LISTEN_DATA_CONNECTION_STATE
I am trying to use "android.permission.PACKAGE_USAGE_STATS" in my app. Here it says that NOTE: This API requires the permission android.permission.PACKAGE_USAGE_STATS, which is a system-level permission and will not be granted to third-party apps. However, declaring the permission implies intention to use the API and the user of the device can grant permission through the Settings application.
It seems that I will need the user to explicitly give my app the permission to give access to the access the usage stats.
In addition, I used the intent code below to open the screen to allow user to give access to my app, but my app is not in the list.
Code I used:
Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
startActivity(intent);
When *startActivity(intent)' is fired (or going to *Settings>Security>Apps with Usage Access), a blank screen below pops up, my app is not part of it.
Bottom line question is -- How to use UsageStatsManager in Android Lollipop? Anyone tried it?
This is what worked for me.
<uses-permission xmlns:tools="http://schemas.android.com/tools"
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />
You can simply make this on the manifest, ignoring just this permission error:
<uses-permission
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions"/>
The AndroidManifest.xml error can be fixed by disabling lint errors. Specifically
Security - SignatureorSystemPermissions
I guess after that the settings app will show your app.