New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: x/mobile: add permission request on android #50104
Comments
How will the Go |
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 |
Thanks. So As this adds a new API, following the proposal process ( https://golang.org/s/proposal ) may still be a good idea. I'll let x/mobile maintainers decide. Thanks. |
yes function will be exported........., so now should I close this and open proposal isues without "Author background"? |
You don't have to open a new one. You can edit this issue to become a proposal. Thanks. |
I hope that it is finally in proposal form |
above I mention jni option, but maybe it is not nessesery: https://developer.android.com/ndk/reference/group/permission |
To check a runtime permission, it seems NDK can be used, but with pid & uid? |
how can i import Java/java/nio/ByteBuffer with gobind? what class or function in android api can be import to go? |
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 |
What version of Go are you using (go version)?
Does this issue reproduce with the latest release?
yes
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..........
More story
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.
Solution Proposal
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:
More story
Add to code to
mobile/app/android.c
or somewhere where it pass best a few functions(or one, it depends on ordering of code) to background (in the fact I suggest the implementation solution, but it will be on implementation team how it will works) and two functions to user interface (the reason of this topic), pattern of these functions is the first answer in ndk request cameraExported 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 RequestPermision(permission string){} // dummy function
.Of course probably IOS has similar system of permission, but I haven't experience for suggest any example...........
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
android_permissions
, but sometime you want only find out whether permission is given and nothing more, therefore I mention this option .....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_permissions
And of course some functions could be "extracted" at init:Like show: https://github.com/golang/mobile/blob/4e6c2922fdeed32d3596616518aaee7b0d79ce55/app/android.c#L71
and https://github.com/golang/mobile/blob/4e6c2922fdeed32d3596616518aaee7b0d79ce55/app/android.c#L78
I m sorry for my English, which is not best.......
EDITED:
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.
ADDED LATER:
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: