Ionic android ask for location permission - android

What I'd like to accomplish:
If the user's location service is preventing me from getting his/her phone's location by default I'd like to ask for location permission on every API between 16-25 (Android 4.1.2-7.1.1)
Since on iOS I haven't met this problem I'd like to focus on android.
What I've already tried:
<uses-permission android:name="android.premission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.premission.ACCESS_FINE_LOCATION" />
cordova-plugin-android-premissions
The plugin mentioned above always returns with hasPermission: true even if the access to location is denied on the device so it's not working for me.
What I haven't tried yet:
cordova-diagnostic-plugin
Diagnostic plugin description says that I have choose between API 23 and above or API 22 and below in my understanding. (<preference name="android-targetSdkVersion" value="22"/> is the minimum target version.) Yet I don't know if it would still work on lower API versions.
My setup:
Cordova CLI: 6.2.0
Gulp CLI & local: 3.9.1
Ionic Framework: 1.3.1
Ionic CLI: 1.7.16
Node: 4.2.2
Device android: 5.0.1
Desired build target: 16
Current build target: 22

Diagnostic plugin description says that I have choose between API 23 and above or API 22 and below in my understanding. ( is the minimum target version.) Yet I don't know if it would still work on lower API versions.
cordova-diagnostic-plugin API level requirements are based around the SDK version being used to build, not the API version running on the target device.
So an app built with SDK for API 23 (Android 6.0) will still work on devices running older versions of Android.
You need to set your build target to API 23 (or above) to build with the primary version of the plugin (cordova.plugins.diagnostic as opposed to cordova.plugins.diagnostic.api-22) because it includes the run-time permissions code which requires a build environment of API 23+.
If the user's location service is preventing me from getting his/her phone's location by default I'd like to ask for location permission on every API between 16-25 (Android 4.1.2-7.1.1)
There's two different aspects to this:
ask for location permission on every API between 16-25 (Android 4.1.2-7.1.1)
Android run-time permissions were introduced in API 23 (Android 6.0)
You can check if the app has location authorization using isLocationAuthorized().
Calling it on a device running Android 5 (API 22) or below will always return TRUE as the permissions are already granted at installation time.
You can request runtime permission to use location with requestLocationAuthorization().
Calling it on a device running Android 5 (API 22) or below will have no effect as the permissions are already granted at installation time.
location service is preventing me from getting his/her phone's location
You can check if user has switched off location using isLocationEnabled().
If location is switched off, you can use switchToLocationSettings() to open the device location settings page to allow user to enable location services, or you can use the cordova-plugin-request-location-accuracy to request the desired location accuracy without needing the user to manually do this on the location settings page.
Disclaimer: I am the author of cordova-diagnostic-plugin and cordova-plugin-request-location-accuracy.

Related

Android Studio Android Phone "Android Version" 9.0 with SDK API v22?

I'm a new Android developer using Android Studio. I've purchased a phone to test my app. My app runs SDK API 27 and higher (i.e., OS Oreo 8+).
My specific question is why does my Android version 9.0 phone have SDK API of 22 rather than SDK API 28?
I purchased a phone that says its running Android 9.0 (Settings->About Phone->Android version = 9.0)
According to wikipedia and other links Android 9 should have SDK APIs of 28.
When I connect the device to Android Studio with USB Developer Mode enabled, I get a red (!) error that Android 9T (minds(API 27) > deviceSdk(API 22))
Additionally, I cannot download my app from Google Play as google play also thinks the API level is too low.
Another interesting thing about the phone is that it won't let me upgrade to Android 10, which I thought it should be able to. When I click the Android 9.0, nothing happens, i.e. 10.0 isn't available.
Sorry! Because of my reputation, I can't comment. As #Mehran B said you may be scammed. First, find IMEI Number of your mobile from the settings. Then go to here
. Type your IMEI Number there and check info like Company Name, Model that matches with your physical device.
Hope helpful!

Instant App, What's the actual minimum sdk

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

How to enable wifi without confirm on android 7.0

I just use wifiwizard to enable WLAN in ionic app.
I have give the app all the permission in the system settings.
Android 5.0 can work without the Pop-ups, but 7.0 always need confirm.
Android 5.0 is based on the older install time permission model, while android 7.0 has run time permission system. This means that on Android 7.0 the permissions to apps are not granted at install time, but rather are requested on the fly during the time when the resource is required to be used.
Read more about it here : Android runtime permission system.

Permission issue on android lollipop device after upgarde

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

In Android Marshmallow App is having all dangerous permission by default

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.

Categories

Resources