Uno-Platform permission problems for android development - android

I am new to the Uno-Plaform development scene and i wanted to create my own speech recognition.
The setup of my speech recognition works with cortana and UWP,
but the setup for my android phone has been creating some problems.
I have added these lines of code to my Android manifest:
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
With these lines of code i should technically be able to record my audio coming from my phone.
System.Exception: 'Error during speech recognition: InsufficientPermissions'
But this is the Exception i get after running it on my android device.
After looking into the android i have found out about dangerous permissions and that these are the cause of my problem.
After many hours of research and testing i have not found a way to open a permission prompt so that i am allowed to use my microphone.
Can anyone explain or help me out with this problem?
Thanks in advance!

Since it's a common requirement, Uno actually offers a few extension to make it easy to request for permissions on Android.
This code is only available on Android
#if __ANDROID__
// This will only check if the permission is granted but will not prompt the user.
bool isGranted = await Windows.Extensions.PermissionsHelper.CheckPermission(ct, Android.Manifest.Permission.RecordAudio);
// This will prompt the user with the native permission dialog if needed. If already granted it will simply return true.
bool isPermissionGranted = await Windows.Extensions.PermissionsHelper.TryGetPermission(ct, Android.Manifest.Permission.RecordAudio);
#endif
Source of that extension is available here

Related

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

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
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
}
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.
You also need to add this to your manifest:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
According to the website below: *App on Marshmallow needs ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission and Location services should be enabled to get wifi scan results. Google probably sees scanning for wifi as a security concern, and wanted to add the location permissions as well.
I would recommend following the blog post below if you are having trouble after adding the ACCESS_COARSE_LOCATION permission to your manifest.
https://www.intentfilter.com/2016/08/programatically-connecting-to-wifi.html
EDIT
For the people down voting, please include a comment explaining why. Was my answer flat out wrong? Did I overlook somthing?
Some more information on google's geolocation service:
Google maintains a huge database for its geolocation service ("Access coarse location" permission). It consists of:
Wifi access point mappings: Wifi MAC address resolve to a geolocation
Cell tower mapping: Cell tower ID's resolve to a geolocation
So it is very possible that this user didn't include this permission and is getting this dialog box.

Cordova Android app and user permissions

I have an Android Cordova app and I'm using GPS, check the network state, read/write on the Documents folder and taking camera pictures. Here my permissions on the manifest XML file:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
The manifest file is auto generated by the Cordova framework. For some reason I don't see camera permissions. Permissions are not asked at installation time anymore (that's since Android 6) but instead they should be asked before usage.
I correctly get the GPS access permission popup but not the read/write Documents folder permission. I also never get the camera permission albeit I'm able to use it without ever being asked for permission. Same story for the Network status permissions (never being asked).
I find Android permissions scheme extremely confusing, under application manager my app has got Location and Storage as expected, Camera and Network status are missing though.
To recap, inside the app, on the actual code, I'm using at least once those devices
GPS fine grained
GPS coarse (probably the Wifi SSID triangulation trick)
Write on Documents
Read on Documents
Read network status (Offline / Wifi / 3G etc..)
Take picture from the camera
Cordova framework wrote this manifest file:
android.permission.ACCESS_COARSE_LOCATION
android.permission.ACCESS_FINE_LOCATION
android.hardware.location.gps (why is it not a .permission?)
android.permission.ACCESS_NETWORK_STATE
android.permission.WRITE_EXTERNAL_STORAGE
On application manager I get those options:
Location
Storage
So basically I get three different sets of permissions :-(
I found this in the this cordova plugin that you mentioned in comments.
So somehow this <uses-permission android:name="android.permission.CAMERA/> have to be in your code so as this plugin can use it.
Maybe you didn't check the right program to see its permissions, or if the camera permission is not shown in application permissions on device, you can't be able to use camera in this application. Please do a check again because I really want to know what is the situation.

How to read from Bluetooth barcode scanner hardware device

I've been trying to get a piece of code to connect to a bluetooth bardcode reader I bought and have tried almost every library in Android Arsenal.
Currently, I am using this one: https://github.com/MacroYau/Blue2Serial
I have all permissions in my manifest:
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
I also request permission when the app opens:
ActivityCompat.requestPermissions(this,
new String[]{android.Manifest.permission.BLUETOOTH,
android.Manifest.permission.BLUETOOTH_ADMIN,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
Manifest.permission.ACCESS_COARSE_LOCATION},
0);
I am able to connect to the scanner device from the app, it pairs up ok. But, when I scan something, I don't see the public void onBluetoothSerialRead(String message) method firing up. It was exactly the very same with all the other libraries I tried. I could pair up, but not read it.
Conversely, if I open a notepad type of app in the same phone and scan it, the contents are immediately written to the notepad.
The scanner device I am using is this one: https://www.zebra.com/us/en/products/scanners/companion-scanners/cs4070.html
Anyone with some tip to give me?
Thank you!
I can think of a few things.
(1) You are reading a 'poorly designed' 2D barcode. Some of the older 'standard' barcodes have simple checksums so lots of random data using a laser based scanner can actually result in a decoded value. If I recall correctly Interleaved 2 of 5 was one of those.
(2) If you enabled 'read all barcodes' its possible that the sub-sequence of codeword (white and black spaces) maps to a valid barcode definition. I would only enable those 2D barcode types that you would be be actually reading.
(3) On the Android side your Bluetooth serial reader isn't picking up the data fast enough. This can be mitigated with the scanner sending prefix/suffix values so that the app knows if you don't get those it was a transmission error.

Is there a way to tell when any application is requesting the use of microphone in Android?

I am trying to determine when any android application instead of only on incoming or outgoing calls, is requesting the use of the microphone. Is there a way to do it programmatically?
Yes, try to use microphone from any of Android built in audio recording classes (e.g. MediaRecorded, AudioRecord) and you will get an Exception raised if someone else is using microphone at the same time (exactly as any resource becomes unavailable if you do not release it in onPause/onDestroy )
The permission you want to ask for is RECORD_AUDIO (http://developer.android.com/guide/topics/security/permissions.html)
Getting the permission of installed apps is described in How to get manifest permissions of any installed Android app.

SMS sending permission on Active Android device

I'm a newbie with android development. So far I have developed an application which uses SMSManager.
I'm testing my application on an active device when it reaches smsManager.sendTextMessage it throws exception of android.premission.SEND_SMS.
I know that I have to get device permission.
My Question is:
Can I send SMS while uploading application right from IDE, or have to install .apk manually?
You must add the following permissions in your Manifest file:
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
If you install the application via debugging/IDE/ADB it will automatically get the permissions you require in your manifest.
So: Yes! When run on the device through the debugger, the application will be able to send test messages.
Bonus information: If you do "stuff" that the application doesn't have the proper permissions for, the debugger will give you exceptions and hints to what is wrong.

Categories

Resources