Android Question Missing permission for GPIO (Android Things)

Status
Not open for further replies.

prokli

Active Member
Licensed User
Longtime User
I created a new project keeping this code:
GPIO example based on Things library:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private ToggleButton1 As ToggleButton
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
   
   If FirstTime Then
     pm.Initialize
    ' Log(pm.GpioList)
     pin4 = pm.OpenGpio("BCM4")
     pin4.Direction = pin4.DIRECTION_OUT_INITIALLY_LOW
     pin17 = pm.OpenGpio("BCM17")
     pin17.Direction = pin17.DIRECTION_IN
     pin17.AddListener("pin17")
   End If
   Activity.LoadLayout("1")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub Pin17_StateChanged (Value As Boolean)
   Dim clr As Int
   If Value Then clr = 0xFF54EF72 Else clr = 0xFFC52D56
   Activity.Color = clr
End Sub

Sub ToggleButton1_CheckedChange(Checked As Boolean)
   pin4.Value = Checked 'turn on or off the led
End Sub

When I run the program code fails at this line: "pin4 = pm.OpenGpio("BCM4")"

Error:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 40 (Main)
java.lang.SecurityException: Caller lacks required permission com.google.android.things.permission.USE_PERIPHERAL_IO
at android.os.Parcel.readException(Parcel.java:2013)
at android.os.Parcel.readException(Parcel.java:1959)
at com.google.android.things.pio.IPeripheralManagerClient$Stub$Proxy.GetGpioClient(IPeripheralManagerClient.java:759)
at com.google.android.things.pio.GpioImpl.<init>(GpioImpl.java:50)
at com.google.android.things.pio.PeripheralManager.openGpio(PeripheralManager.java:197)
at anywheresoftware.b4a.objects.PeripheralManagerWrapper.OpenGpio(PeripheralManagerWrapper.java:45)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.example.main.afterFirstLayout(main.java:104)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

I added all the things to the manifest editor as suggested by the example:

AddApplicationText(<uses-library android:name="com.google.android.things"/>)
AddPermission(com.google.android.things.permission.USE_PERIPHERAL_IO)


Thanks for any help!
 

prokli

Active Member
Licensed User
Longtime User
Yes I recognized this hint:

If you are getting an error similar to:

java.lang.SecurityException: Caller lacks required permission com.google.android.things.permission.USE_PERIPHERAL_IO

Then reboot the device. Your app should then have this permission.

I restarted my device and run in Debug mode again. I get still an error when doing this line of code
B4X:
pin4 = pm.OpenGpio("BCM4")
 
Upvote 0

DC1

Member
Licensed User
Longtime User
I'm having difficulties with io-permissions with Android Things 1.0.14, the solution highlighted above #4, only partially worked -
I get a list of errors in the Log stating with this :-

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/things/pio/PeripheralManager;

Anyone got any ideas ?

This whole Android Things process is very frustrating :eek::eek::eek::eek:
 
Upvote 0
Status
Not open for further replies.
Top