I have built an app with android sdk version 22 and now I want to upgrade it with sdk 23. I know that from Android 6.0 onwards user would have to allow or deny dangerous permissions at runtime. But in my case when I compiled my app with sdk 23 and run it on a Android Android 6.0 device(I tried with two devices) I can see the app is not crashing and all the dangerous permissions which are enlisted in Manifest are given by default. Can someone please help me finding out why this is happening?
Have you changed TargetSDK to 23?
Android checks the target sdk and loads apis of that target. Here even though you are compiling it to 23, android thinks that Marshmallow apis are not used and hence defaults to previous API. So run time permissions are not checked.
Related
As per the android developers site, minimum sdk for Instant app is 21, ie 5.0.
link
The site clearly states : Android Instant Apps are available on the majority of devices running Android 5.0 (API level 21) and higher.
But when we create a new project as per the guideline given in this link
which states that we need to have minimum sdk of 23, to get instant app support.
And does not allow me to create a support for 5.0.
as shown in below image which I tried :
That requirement exists only in the setup wizard, and it is a bug. If you change the value to something lower after creating the project, you'll see that it builds fine and can run on API 21 and 22 devices.
The documentation is correct about supported Android versions, but note that even that doesn't dictate any particular minSdkVersion. You can build an instant app with a minSdkVersion lower than 21. It just won't run on anything before 21, since the Instant Apps Runtime itself is restricted to 21+.
For that reason, this check was always a bug, even when we didn't support devices before 23. I was told it was fixed in 3.0, though I didn't verify. I checked tonight and confirmed that the check is still present in 3.0. Could be fixed in a more recent version. But if not, we need to fix that. I'll follow up.
That requirement might be due to android run-time permission support Requesting Permissions at Run Time as official document mention
Note: Beginning with Android 6.0 (API level 23), users can revoke permissions from any app at any time, even if the app targets a lower API level. You should test your app to verify that it behaves properly when it's missing a needed permission, regardless of what API level your app targets.
Currently it has been fixed with android studio 3.1 Canary 5
For instance app minimum API 23: Android 6.0 (Marshmallow).
Please follow this link https://developer.android.com/topic/instant-apps/getting-started/first-instant-app.html
If I was not given any targetversion in gradle then, is it will take latest version, or which version it will choose, I build the apk without giving any targetversion, so when I will get problem of this targetversion is mandatory?
Its Not mandatory but is strongly recommended.
targetSdkVersion has nothing to do with adding the latest version or your compiling, it will just allow you to use the features available in the SDK you are targeting.
For example.
If you are targeting SDK 23, Then IDE will mark you errors whenever you are using critical permissions in your code. it will tell you to put a permission check.
If you target SDK 22, then you are free to use critical permissions without putting a permission check.
for the above situation, your app is tested and works fine in Lollipop or below, but it might crash in Marshmallow.
as per Documentation, it says here
Specifies the API Level on which the application is designed to run.
In some cases, this allows the application to use manifest elements or
behaviors defined in the target API Level, rather than being
restricted to using only those defined for the minimum API Level.
I have updated my device few days ago. Its an lollipop upgrade, but still it started asking permissions for my app at run time.
I have targetSDK 21
But when I open app it pops up for gps permission and if user denied it, it stops working.
I also used checkSelfPermission but it is retuning Granted(0) every time even user denied it.
My current android version of Phone is android 5.1.1
Device having android 5.1.1 but its OS is customised by MI like samsung phones. So after upgrade it started asking permission for resource like GPS, Contact and other. Its android sdk version is android 5.1.1 not Android 6.0 which have Runtime Permissions.
You require to implement runtime permission check for Android-21 plus device. Check the solution over here. You will find how array has been utilized in that, mostly that is were user stucks.
Additionally, if denied then you cannot force user to use that functionality. In short you need to bypass that module.
Lollipop have no runtime permission mechanism.
Runtime Premission came up with Android M.
change the sdk version under gradlebuild minSdkVersion 20 check from here https://developer.android.com/about/versions/android-5.0.html
Is there any way to get around the new Android 6.0 Permissions system if you need to build your App for Android 6.0 and use it on a 6.0 Device?
I ask because there are so many Apps in the App Store which are not asking for any permissions and that's kinda weird. For me that means there are two possibilities.
They all are not compiling their apps for android 6.0
They are somehow getting around the new permissions system using android 6.0
So is there a way around?
Change your targetSDK to 22 will work on all device without permissions runtime, If your targetSDK is 23 than you have to set permission you can't overcome this.
This is an easy question and I would really be helped if somebody would confirm my idea.
There is a new feature/change in Android 6, that are the runtime permissions, where apps do not query for permissions at run time, but instead during the time they really use the featre. It's a great idea, but supporting it would require me to change code and I would rather not code more Java than absolutely necessary.
Hence, if I do not really need the features of API 23 (Android 6) features, can I simply use the API 22 version and keep my code unchanged, yet able to run on Android 6 phones?
My take is that a new Android Version is compatible with at least some previous API versions, and else all apps would need to be updated.
Hence, if I do not really need the features of API 23 (Android 6) features, can I simply use the API 22 version and keep my code unchanged, yet able to run on Android 6 phones?
TL;DR: you do not need to deal with runtime permissions, but not for the reasons that you cite.
What controls whether your app has to deal with runtime permissions is your targetSdkVersion. If that is 23 or higher, you have to handle runtime permissions in your Java code. If that is 22 or lower, you do not, though the user can still revoke permissions through Settings.
targetSdkVersion affects some, but not all, features of an API level. Usually, the things that it affects are written up in the JavaDocs for the Build.VERSION_CODES value, but for whatever reason, Google decided not to bother.
Whether you can code to any API Level 23 features is tied to your compileSdkVersion. There are many things in an API level that are not affected by targetSdkVersion, such as new classes and new methods. In your case, you indicate that you do not need any of this, which is fine. However, compileSdkVersion does not affect whether Android 6.0+ requires you to implement runtime permission logic in the Java code; targetSdkVersion does.
Eventually, something is going to force your hand to raise your targetSdkVersion to 23 or higher. At that point, you will need to "bite the bullet" and deal with the runtime permissions.
If you compile your app at API 22, you won't be able to use any feature of API 23. And your app will behave normally on API 23 as it does on API 22.
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.
Requesting Permissions at Run Time