// http://zadjhu.blogspot.com/2013/03/android-jellybean-does-not-allocate.html public void ShellAsync(string e, Action<string> y) { // http://a3nm.net/blog/android_cli.html #if Android // http://www.android.pk/blog/general/launch-app-through-adb-shell/ // am start -a android.intent.action.MAIN -n com.android.settings/.Settings // am start tel:210-385-0098 // am start -a android.intent.action.CALL tel:245007 // am start -a android.intent.action.SENDTO "sms:5245007" -e "sms_body" "heyy" && input keyevent 22 && input keyevent 66 // am start -a android.intent.action.SENDTO -d sms:1234567890 --es sms_body ohai --ez exit_on_sent true // am start -a android.intent.action.SENDTO -d smsto:245007 --es sms_body ":*" --ez exit_on_sent true && am start -a android.intent.action.SENDTO -d sms:5245007 --es sms_body ":*" --ez exit_on_sent true && input keyevent 22 && input keyevent 66 // pm list packages // pm list packages -f //http://stackoverflow.com/questions/11201659/android-adb-shell-dumpsys-tool // am start -S -e sms_body 'your message body' \ //-e address receiver -t 'vnd.android-dir/mms-sms' \ //com.android.mms/com.android.mms.ui.ComposeMessageActivity \ //&& adb shell input keyevent 66 //am start -n com.google.android.youtube/.PlayerActivity -d http://www.youtube.com/watch?v=MTT-crZBB0k // http://stackoverflow.com/questions/7095470/android-read-send-text-messages-on-ubuntu // System.InvalidOperationException: Sequence contains more than one element //at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source) //at jsc.Languages.Java.JavaCompiler.GetArrayEnumeratorType() in x:\jsc.internal.svn\compiler\jsc\Languages\Java\JavaCompiler.overrride.cs:line 52 //at jsc.Languages.Java.JavaCompiler.GetImportTypes(Type t, Boolean bExcludeJavaLang) in x:\jsc.internal.svn\compiler\jsc\Languages\Java\JavaCompiler.WriteImportTypes.cs:line 363 //at jsc.Languages.Java.JavaCompiler.WriteImportTypes(Type ContextType) in x:\jsc.internal.svn\compiler\jsc\Languages\Java\JavaCompiler.WriteImportTypes.cs:line 22 //at jsc.Languages.Java.JavaCompiler.CompileType(Type z) in x:\jsc.internal.svn\compiler\jsc\Languages\Java\JavaCompiler.CompileType.cs:line 43 //at jsc.Languages.CompilerJob.<>c__DisplayClass1a.<CompileJava>b__17(Type xx) in x:\jsc.internal.svn\compiler\jsc\Languages\Java\CompilerJob.cs:line 120 // IsArrayEnumerator: ScriptCoreLib.Shared.BCLImplementation.System.__SZArrayEnumerator`1, ScriptCoreLibAndroid, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null //IsArrayEnumerator: ScriptCoreLib.Shared.BCLImplementation.System.__SZArrayEnumerator`1, ScriptCoreLibJava, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null try { // http://stackoverflow.com/questions/9062182/android-icmp-ping // https://gist.github.com/micahasmith/5084997 var p = new java.lang.ProcessBuilder(new[] { "sh" }).redirectErrorStream(true).start(); var os = new java.io.DataOutputStream(p.getOutputStream()); //os.writeBytes(e + '\n'); os.writeBytes(e + "\n"); os.flush(); // Close the terminal os.writeBytes("exit\n"); os.flush(); // read ping replys var reader = new java.io.BufferedReader(new java.io.InputStreamReader(p.getInputStream())); string line = reader.readLine(); while (line != null) { y(line); line = reader.readLine(); } } catch (System.Exception ex) { y("AndroidShellAsync error: " + new { ex.Message }); } #else y("ShellAsync not implemented."); #endif }
public static Process Start(string fileName, string arguments) { // Z:\jsc.svn\examples\java\hybrid\ubuntu\UbuntuTCPMultiplex\Program.cs //Console.WriteLine("enter Start " + new { fileName, arguments }); var x = new __Process { }; // http://stackoverflow.com/questions/19030625/redirecting-output-of-a-process-with-process-builder try { var aa = new List<string> { fileName }; aa.AddRange( // jvm wants em split arguments.Split(' ') ); //var a = new[] { fileName, arguments }; //var o = java.lang.Runtime.getRuntime().exec(aa.ToArray()); //x.InternalProcess = o; var p = new java.lang.ProcessBuilder(aa.ToArray()); var pp = p.redirectErrorStream(true); x.InternalProcess = pp.start(); // http://stackoverflow.com/questions/26174975/fire-a-cmd-exe-command-through-processbuilder-with-visual-window // can we send input? x.StandardInput = new StreamWriter( new __NetworkStream { InternalOutputStream = x.InternalProcess.getOutputStream() } ); //InputStreamExtensions.ToNetworkStream( //var sout = x.InternalProcess.getOutputStream(); var sout = new StreamReader( x.InternalProcess.getInputStream().ToNetworkStream() ); //var n = new __NetworkStream { InternalOutputStream }; //InputStreamExtensions new Thread( delegate() { try { var xx = sout.ReadLine(); while (xx != null) { Console.WriteLine(xx); xx = sout.ReadLine(); } } catch { } x.InternalConsoleReady.Set(); } ).Start(); } catch (Exception err) { Console.WriteLine(new { err.Message, err.StackTrace }); //throw err; //throw; throw new InvalidOperationException { }; } //Console.WriteLine("exit Start "); return x; }
public static Process Start(string fileName, string arguments) { // Z:\jsc.svn\examples\java\hybrid\ubuntu\UbuntuTCPMultiplex\Program.cs //Console.WriteLine("enter Start " + new { fileName, arguments }); var x = new __Process { }; // http://stackoverflow.com/questions/19030625/redirecting-output-of-a-process-with-process-builder try { var aa = new List <string> { fileName }; aa.AddRange( // jvm wants em split arguments.Split(' ') ); //var a = new[] { fileName, arguments }; //var o = java.lang.Runtime.getRuntime().exec(aa.ToArray()); //x.InternalProcess = o; var p = new java.lang.ProcessBuilder(aa.ToArray()); var pp = p.redirectErrorStream(true); x.InternalProcess = pp.start(); // http://stackoverflow.com/questions/26174975/fire-a-cmd-exe-command-through-processbuilder-with-visual-window // can we send input? x.StandardInput = new StreamWriter( new __NetworkStream { InternalOutputStream = x.InternalProcess.getOutputStream() } ); //InputStreamExtensions.ToNetworkStream( //var sout = x.InternalProcess.getOutputStream(); var sout = new StreamReader( x.InternalProcess.getInputStream().ToNetworkStream() ); //var n = new __NetworkStream { InternalOutputStream }; //InputStreamExtensions new Thread( delegate() { try { var xx = sout.ReadLine(); while (xx != null) { Console.WriteLine(xx); xx = sout.ReadLine(); } } catch { } x.InternalConsoleReady.Set(); } ).Start(); } catch (Exception err) { Console.WriteLine(new { err.Message, err.StackTrace }); //throw err; //throw; throw new InvalidOperationException { }; } //Console.WriteLine("exit Start "); return(x); }