Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get "requesting permission to use WLAN. Allow?" prompt window in real mobile phone?

Tags:

android

kotlin

I use the Code A to set the enabled status of WiFi, it works well when I use Android Emulator with both API 26 and API 23 in Android Studio 3.1.3 , and none of prompt window display!

But I get a prompt window "An App is requesting permission to use WLAN. Allow?" in real mobile phone with Android 5.1 when I run the code A.

How can I make the prompt window not to display in real mobile phone? Thanks!

BTW,the real mobile phone is Samsung SM-J5008 with Android 5.1

Prompt Window

enter image description here

I have set the permissions

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

Code A

fun setWiFi(aWiFiDef: WiFiDef): Unit{
    val wifiManager =mContext.applicationContext.getSystemService(WIFI_SERVICE) as WifiManager
    wifiManager.isWifiEnabled=aWiFiDef.status        
}
like image 611
HelloCW Avatar asked Jun 25 '18 13:06

HelloCW


Video Answer


1 Answers

Android 5.1 does not have such runtime permission, so I assume, that this is a wrongly implemented permission request rational, which is shown even though the app does not need to. You wrote, that you tested with API level 26 and 23, which is Android 6.0 and higher, so these versions already have runtime permissions. Maybe you haven't seen this issue, because you haven't tested on devices below Android 6.0...

Please check if you somewhere call AppCompat.shouldShowRequestPermissionRationale() and if it is surrounded by SDK level checks or at least with a checkSelfPermission as described here: https://developer.android.com/training/permissions/requesting. Test your code in an emulator with Android 5.1 and Android 6.0. Then you should be able to reproduce that issue also on real phones.

like image 54
Denis Loh Avatar answered Sep 23 '22 10:09

Denis Loh