android:targetSdkVersion="23" Crashes so Galaxy S6 - android

Simply changing from android:targetSdkVersion="22" to "23" causes my app to crash on the Galaxy S6. What would cause that? Rolling back and everything is fine.
I don't have an S6 so I cannot replicate - I'm sure it is something simple...

The most likely cause is the permissions required by your app, specified in your Manifest.
"Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app."
See Requesting Permissions at Run Time
In particular if your app requires any of the permissions listed in the Dangerous permissions and permission groups table, you will need to implement code to ask for those permissions at runtime on devices running 23 or higher. If you don't, and you try to perform a task that requires one of these permissions, the app will crash.
Normal (Non-dangerous) permissions however, are automatically granted by the system if required, and do not need to be individually requested at run time.
If you want to avoid this issue, just leave your target SDK as 22.
If there are other features of SDK 23 that you particularly need then you will need to go through the steps indicated in the first link above so that permissions are requested at run time on devices running 23 or higher.
Marshmallow (23) has been rolled out for the Galaxy S6 in many regions now. If you can find out what Android version the Galaxy S6 that is experiencing the crash is running, I bet you'll find it's Marshmallow.

Related

TelephonyManager.getCellLocation crashing asking for READ_PHONE_STATE permission in some devices

We use the method getCellInfo from TelephonyManager in our app and it's been working fine without any issues except for a very very few devices where it's crashing with the following message
java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10215 nor current process has android.permission.READ_PHONE_STATE
However, the documentation doesn't say that we require this permission for invoking this method. Also, we're not asking for this permission at all. Has anyone faced this issue. I'm guessing that this might be a general problem with permissions itself? We're targeting sdk version 22, minSdkVersion is 15.
My app has the same problem when using TelephonyManager. Its targetSdkVersion is 27 and minSdkVersion is 17.
According to the crashing report of my app from Google Play Console, the phones that have this SecurityException problem are Oppo, LG, Asus and Sony phones which have Android 5.0-5.1. After that, I ran my app on the emulator of Android Studio with Android 5.0 and 5.1. I found that it will crash because of not having READ_PHONE_STATE permission.
Therefore, I think that this issue will happen to most devices with Android 5.0 or 5.1, nothing with the brands of the phone.
The solution is to add the following code to the AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_PHONE_STATE" android:maxSdkVersion="22"/>
I set the maxSdkVersion of this permission to 22 because this SecurityException will not happen after Android 6.0, so this permission is not needed for the phones with Android 6.0 or newer.

Understanding Android 6.0 with targetSDK=22 behaviour

I have app (current targetsdkversion is 23) running in version 4.4 & 5.1 but with 6.0 It requires run time permssion.
This needs some coding changes I prefer to defer for sometime. Is it perfectly okay change the targetsdkversion to 22 instead of 23. Does this allow app to be run in 6.0 without using 'run-time permission'? I read app mayn't properly if user decides to change the permission after installation. Im okay with this limitation for now.
Be careful if you have already published the app with targetSdkVersion of 23, those users who have installed it will not be able to "upgrade" to a new version of your app because of the target SDK downgrade. They'll have to uninstall then re-install your app.
But, to answer your question about API levels, yes it will run fine on Marshmallow with target SDK set to 22. The users will be presented with an old style permission accept dialog when installing the app and all permissions will be granted at install time. However, users could go in a disable the permissions via Settings so your app could start receiving SecurityException for protected operations.

Difference Between uses-permission-sdk-23 and uses-permission?

I just come to know newer tag in android manifest file called "uses-permission-sdk-23"
<uses-permission-sdk-23 android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.CAMERA" />
Can anybody please provide difference between this two?
Summary
<uses-permission> applies to all SDKs and <uses-permission-sdk-23> will apply the permission only to SDK 23+.
When should you use <uses-permission-sdk-23>?
For Android SDK 23 and above, you have the option to request the permission at runtime but the permissions will be in their default state upon installation and the user will not be prompted at installation. (Essentially this can be used to prompt the user to grant the permission on a need-to-use basis and you have the opportunity to provide an explanation of why it's needed.)
However, for SDK 22 and below, the user is prompted at installation for permissions. As some permissions can seem suspicious or dodgy to the user, you may not want to request these for SDK 22 and below as you can't provide an explaination of why you need them beforehand, hence the <uses-permission-sdk-23> tag.
Additionally: the documentation is unclear as to whether sdk-23 permissions also cause the app to be filtered in the Play Store, but if it was your intention to do this, the documentation recommends that you make use of <uses-feature> elements instead to declare hardware compatability.
Recommendation
Generally, it is considered best practice to use <uses-permission-sdk-23> if your app does not need to support SDK 22 and below, or if the permission you are requesting is not needed for SDK 22 or below as it is then clear that this permission is requested at runtime.
Otherwise, <uses-permission> should be used as this is backwards compatible and the behavior will be correct on any SDK version; 22 and below, permissions will be requested at installation. 23 and above, it's up to you to request at runtime.
You should request permissions at runtime wherever possible as it allows you to explain to your user why you need certain permissions rather than just prompting them with a list of permissions at install time when the user has likely not established trust in the app.
Notes
Both of these accept a maxSdkVersion attribute that can be used when a permission was required for older devices but is not required for newer devices. (For example, the WRITE_EXTERNAL_STORAGE example shown in the Android documentation.)
Reference: (Android Documentation)
if the app is running on a device with SDK version 23 or higher. If the device is running SDK version 22 or lower
when you update an app to include a new feature that requires an additional permission. If a user updates an app on a device that is running SDK version 22 or lower, the system prompts the user at install time to grant all new permissions that are declared in that update. If a new feature is minor enough, you may prefer to disable the feature altogether on those devices, so the user does not have to grant additional permissions to update the app. By using the uses-permission-sdk-23 element instead of uses-permission
you can request the permission only if the app is running on platforms that support the runtime permissions model, in which the user grants permissions to the app while it is running.
for More info refer this.uses - Permission sdk 23
By using the <uses-permission-sdk-23> element instead of <uses-permission>, you can request the permission only if the app is running on platforms that support the runtime permissions model, in which the user grants permissions to the app while it is running.
This has been introduced to support runtime permission feature of Marshmallow (API-23) onwards.
This simply specifies that an app wants a particular permission, but only if the app is running on a device with SDK version 23 or higher. If the device is running SDK version 22 or lower, the app does not have the specified permission.
This element is useful when you update an app to include a new feature that requires an additional permission. If a user updates an app on a device that is running SDK version 22 or lower, the system prompts the user at install time to grant all new permissions that are declared in that update.
You can reffer to the documentation.
user-permission-sdk-23 specifies that the app that wants a particular permission is running on SDK version 23 or higher.
It is used when you update your app to run SDK 23 elements and the users running a lower API which does not support the new elements.
Android manifest - user permissions
Specifies that an app wants a particular permission, but only if the app is running on a device with API level 23 or higher. If the device is running API level 22 or lower, the app does not have the specified permission.
see the documentation
uses permission
Use
<uses-permission-sdk23>
to apply permission for Marshmallow devices only.

Android M "Runtime Permissions" not requested at runtime?

I was getting ready for runtime permissions on android M when I recently figured out that (at least on theGgalaxy S6 of my friend), still all permissions have to be confirmed at installation time (Google Play).
He has Android M, and sure you can revoke the permissions in the app settings now, but initially when you start the app after install, everything is granted.
I am kind of surprised, that's not the "Runtime Permissions" I was expecting.
Any hints on that? Did I miss something?
According to the doc:
This lesson describes how you implement permissions requests on apps that target API level 23 or higher, and are running on a device that's running Android 6.0 (API level 23) or higher. If the device or the app's targetSdkVersion is 22 or lower, the
system prompts the user to grant all dangerous permissions when they
install or update the app.
The runtime permissions will only take effect if you update the target SDK to 23

Marshmallow Permissions not working for TargetVersion below 23

My project is a long running project. I had set the target version as 10, 4 years back. I cant change the target version to 23, since I am using httpImageCache and also having issues with UI's. My problem is, when Marshmallow released I tried to integrate Marshmallow with targetVersion 10,
int returnedPermission = ContextCompat.checkSelfPermission(MyActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
this function is always returing '0' if I manually ON or Off storage permission from App Settings page. Can any one please help me?
As #Commonware has already given the answer, but here I am adding more detail to the question which might help you.
As per the official android developer site:
If the device is running Android 5.1 or lower, or your app's target
SDK is 22 or lower: If you list a dangerous permission in your
manifest, the user has to grant the permission when they install the app; if they do not grant the permission, the system does not install the app at all.
If the device is running Android 6.0 or higher, and your app's target
SDK is 23 or higher: The app has to list the permissions in the
manifest, and it must request each dangerous permission it needs
while the app is running. The user can grant or deny each permission,
and the app can continue to run with limited capabilities even if the
user denies a permission request.
As your target SDK is 10, application will run perfectly like previous. Anyway please note that user still can revoke a permission after that..!!! Although Android 6.0 warn the user when they try to do that but they can revoke anyway.
Above statement is taken from official android developer site.
Can any one please help me?
Delete that code, as it is useless for you. If your targetSdkVersion is below 23, you cannot find out whether or not the user revoked permissions.
use PermissionChecker.checkSelfPermission()
when targetSdkVersion <= 22,you also can use requestPermission()

Categories

Resources