2

I am working on an android project where I use a phone to power an external device. Through a USB-OTG connection, I can power the external device.

I want to know if I can write a program on android studio where I can press a button in the app to toggle the power to this external device (turn it on and off).

I've seen it done before on an older Samsung Galaxy 3 phone (on a much older version of android) by updating data in a file; specifically this file:

/sys/devices/virtual/host_notify/usb_otg/mode

But I'm trying to write the software so it is more generic and can work on any new android device.

Is there a way to do what I need?

NicoCaldo
  • 1,171
  • 13
  • 25
Adam Higgins
  • 705
  • 1
  • 10
  • 25
  • 1
    "I want to know if I can write a program on android studio where I can press a button in the app to toggle the power to this external device (turn it on and off)." Sorry, I highly doubt that something like that is possible. I did some research on that idea a while ago and it seems that this feature is not supported. – TheScribbler2019 Aug 02 '19 at 12:09
  • 1
    It seems difficult, but I've seen it working with that old Samsung, so I just need a way to do it on a newer version of android – Adam Higgins Aug 02 '19 at 13:28
  • 1
    Ok, let's assume it might be possible. You probably would need to root your phone and then rewrite some script and replace it inside the system. I'm interested and will do some research but there won't be a fast and seriously no easy solution, if there is even one out there. I will keep you updated if I find something. – TheScribbler2019 Aug 04 '19 at 11:20
  • The way I found to do it on a moto G6 was with the file /sys/class/power_supply/usb/usb_otg. I write 0 into the file to stop the power output and 3 into the file to resupply the external device, but nothing generic has come my way during the research. – Adam Higgins Sep 12 '19 at 13:24

1 Answers1

1

I've tried finding a generic way to do this but it doesn't seem possible because the only way I've seen it possible is by using shell commands to toggle exposed kernel bits through root files.

I have concluded it's likely impossible to make generic code for this as most android phones root files are organised differently. So you need to discover the specific file each time you want to use a different phone for the software.

I don't think it would be feasible for myself to create a database of different brands of phones root file structures because new phones come out all the time with new structures which would require too much maintenance on my behalf.

Adam Higgins
  • 705
  • 1
  • 10
  • 25