0

I need to run Android command like this below from C# Unity3D Android app.

How it can be done?

adb shell am broadcast -a "ACTION_HIDE_STATUSBAR" --ei "ui" 2 --ez "state" true
Fattie
  • 27,874
  • 70
  • 431
  • 719
seek
  • 1,065
  • 16
  • 33
  • You can't unless the device has been rooted. – Gusman May 05 '16 at 08:17
  • Then use Process.Start, like any other C# program. – Gusman May 05 '16 at 08:18
  • Simply -- Process.Start("am broadcast -a \"ACTION_HIDE_STATUSBAR\" --ei \"ui\" 2 --ez \"state\" true"); -- Doesn't work, so I think that it must be other method or I'm doing something wrong.. The same command from shell works of course. – seek May 05 '16 at 08:31
  • Youre doing it wrong, anything after am must be passed as parameters to Process.Start – Gusman May 05 '16 at 08:48
  • System.Diagnostics.Process.Start("am", "broadcast -a \"ACTION_HIDE_STATUSBAR\" --ei \"ui\" 2 --ez \"state\" true"); - this didn't work also. I think that will be easier if you can tell me how correct method should be - maybe in answer? – seek May 05 '16 at 08:59
  • the previous line you pasted should be the right one, does it raise any exception or error message? – Gusman May 05 '16 at 09:45
  • No nothing showed on the debug console – seek May 05 '16 at 09:47
  • Use this pastebin: http://pastebin.com/Wt55bcHg that will output the exit code, that will give on the console the exit code, what will give us more info on why it doesn't works – Gusman May 05 '16 at 09:55
  • I run this on Android so I change Console.WriteLine to Debug.Log.. but it doesn't write nothing. It's strange :/ – seek May 05 '16 at 10:12
  • Hmmm, are you sure your function is being executed? – Gusman May 05 '16 at 10:23
  • Yes I'm sure. Fuction jusr after this was executed. – seek May 05 '16 at 10:28
  • @Gusman I'm sorry it was executed just before my Debug gui console was loaded. Now I have exit code 255 – seek May 06 '16 at 06:51
  • BTW. @Joe Blow why Unity3D tag was not correct for this question in your opinion? – seek May 06 '16 at 08:20
  • Ok, am is a Java program and standard exit codes are only 0,1, it should be a custom code but I can't find it in the Am source code. Try to redirect the standar output stream of the process and read it with an StreamReader, it will return what the program would show on the console, so there should be the error message. But my bet is your process does not have privileges to execute am, this can give you a hint on how to run your app as administrator: http://stackoverflow.com/questions/9194725/run-android-program-as-root – Gusman May 06 '16 at 09:13

1 Answers1

0

I ended up by modified UnityPlayerActivity class after exporting to Android project.

After more research it seems that this is the only solution or alternatively it can be done via java plugin in similar way.

seek
  • 1,065
  • 16
  • 33