ksksue / PhysicaloidLibrary

Android Library for communicating with physical-computing boards (e.g.Arduino, mbed)
http://www.physicaloid.com/
354 stars 151 forks source link

USB host permissions with Android 9 (Pie) #35

Open otraupe opened 5 years ago

otraupe commented 5 years ago

I am trying to use an Arduino with a rooted Xiamo Pocophone F1 flashed with LineageOS 16. I am struggling how to get the user permission for USB host mode. I just don't know how to do it. Can someone help? Plugging the Arduino does not create an intent, so getting the permission on the fly does not seem to work. And I don't know the explicit "name" of the permission. So I don't know what to query. Thanks!

xxxajk commented 5 years ago

See here: https://github.com/xxxajk/PhysicaloidLibrary Permissions are in the manifest. The owner of this repository has not been around for years. It is obsolete.

otraupe commented 5 years ago

Thx for the reply!

All I can see is the "uses-feature" statement. But in modern apps you need to provide "uses-permission", as well. And you also need to actively query the needed permissions. This does not happen automatically any more. I only don't know its name.

I even saw evidence that this permission can be vendor-specific as e.g. in "com.sonyericsson.usbotg.SOMETHING".

otraupe commented 5 years ago

Actually, I don't see any permissions at all in the code. Am I looking at the wrong Manifest?

xxxajk commented 5 years ago

https://github.com/xxxajk/PhysicaloidLibrary/blob/master/SampleProjects/PhysicaloidTest/AndroidManifest.xml See line 11.

otraupe commented 5 years ago

That is the "uses-feature" statement. How does this work as permission? With modern sdk versions at least it does not.

xxxajk commented 5 years ago

Works fine here, on marshmallow...

otraupe commented 5 years ago

Did you just run these examples or did you try to use the permission in your own code? I can't seem to create an app with this "permission" which actually asks me for permission. It seems I have to use a very old "target SDK", but I struggle with that.

xxxajk commented 5 years ago

Android will always ask for permission. That's normal.

otraupe commented 5 years ago

That exactly is the point: it does not. :)

Lauszus commented 5 years ago

This has been the case for some time. You need to request permission inside the application. Please refer to one of my apps:

https://github.com/Lauszus/FaceRecognitionApp/blob/f67687eba2c9b6d9cbad69322dc6a297e21327bb/app/src/main/java/com/lauszus/facerecognitionapp/FaceRecognitionAppActivity.java#L545-L547

https://github.com/Lauszus/FaceRecognitionApp/blob/f67687eba2c9b6d9cbad69322dc6a297e21327bb/app/src/main/java/com/lauszus/facerecognitionapp/FaceRecognitionAppActivity.java#L488-L500

For more information see: https://developer.android.com/training/permissions/requesting.

For more information requesting USB host permission on Android: https://developer.android.com/guide/topics/connectivity/usb/host#permission-d.

otraupe commented 5 years ago

Lauszus, thank you very much! I tried to follow the instructions on google developers closely: https://developer.android.com/guide/topics/connectivity/usb/host#permission-d

I did not find them very straight forward and in particular did not understand that the permission string used there can be an arbitrary dummy string.

Now I finally found out, how it works. It seems there is no good tutorial out there. Maybe I write one.