proposal: x/mobile: add permission request on android #50104
What version of Go are you using (go version)?
Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (go env)?
go env Output
What did you do?
I was found problem: is no easy way how request permission by runtime..........
I m interesting in programing android apps with go, I have created small library for my (experimental) project, the library is trying implement bluetooth socket ....., but I have problem with manifest (androids ignore Bluetooth permission........), I was trying to fix(by runtime), then I realize that there is not easy way how request permission by runtime.........., I was writing this problem to fyne-io/fyne, which forms the graphics library of my experimental project, but now I think it is issue to gomobile.
The Solution would be use existing way how from ndk request permission. It would add two functions to programmer (user) interface. It is support with ndk solution:
Add to code to
Exported GO side (main Proposal)
func RequestPermision(permission string)Next code would use RunOnJVM from "mobileinit" package, it would have argument like "permission string" but in final version it could be "permission int", the code call `C.android_permissions(env, n)`, which could be void or return something, in further code is void ...
Other OS (IOS) should have:
func IsPermision(permission string) bool
The next exported function would have similar situation with argument like previous one - I do not know whether solution of type functions is the best..... and in the fact it: it would unnecessary function, could be skipped because it could be execute at the beginning
Unexported - Background C side (of course only example how it could be done)
void android_permissions(JNIEnv* env, char* perm_name)In this example it is void, but it could be string (char*) or bool and of course argument could be int, at the beginning function control whether permission would be granted and after that if it was not granted it would be call function to "real" request.:
void android_request_permission(JNIEnv* env, char* permissions)It would be call ndk java api to granted permission.
bool android_has_permission(JNIEnv* env, const char* perm_name)The function to check whether permission is granted:
jclass android_permission_name(JNIEnv* env, const char* perm_name)The function to get permission class from (char*) string:
static jmethodID request_permissionsAnd of course some functions could be "extracted" at init:
Like show: https://github.com/golang/mobile/blob/4e6c2922fdeed32d3596616518aaee7b0d79ce55/app/android.c#L71
I m sorry for my English, which is not best.......
Of course there is further reason, why implement this request: dangerous permission: https://developer.android.com/training. Yes I know that golang isn't primary for android and majority of request will never need (because missing API), but there are some permissions, which gomobile could use ..............., for example above mentioned Bluetooth.
I have made some prototype of this (it is working on my android simulator): https://github.com/MatejMagat305/golang-prototype-permision (without adding to current code, only use function RunOnJVM) - it is only prototype which probably contains memory leak and maybe it should be good added or change functions to request multiple strings ............... And yes, something similar is on IOS, but I haven't suitable device, experience and internet claim that work a little bit diferent
The text was updated successfully, but these errors were encountered:
So my english is not the best, therefore I´m sorry if I missanderstood........., so in my opinion it is (relative) small piece of code, which will need add to x/mobile and it do´nt need add extra files or infrastrukture, because all things are in current code......... ( now I was edited original for some mistake), yes I sugest only one function for users and that is
you can not direcly do this, you must do this
for example I try bring to go (fyne) android bluetooth: https://github.com/MatejMagat305/fyne-x/blob/master/driver/bluetooth/bluetooth_and.go