Ejemplo n.º 1
1
		public override void run()
		{
			try
			{
				java.io.InputStreamReader isr = new java.io.InputStreamReader(_is);
				java.io.BufferedReader br = new java.io.BufferedReader(isr);
				String line=null;
				while ( (line = br.readLine()) != null)
				{
					Debug.WriteLine(_type + ">" + line); 
				}
			} 
			catch (Exception ex)
			{
				Debug.WriteLine (ex);
			}
		}
        static string InternalGetSDKVersion()
        {
            var version = "";
            var w = "";

            try
            {
                // by now we have webclient?
                // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201412/20141207
                var url = new java.net.URL(SDKVersionLocation);

                HttpURLConnection con = (HttpURLConnection)url.openConnection();

                int CONNECT_TIMEOUT_MILL = 2000;
                int READ_TIMEOUT_MILL = 900;

                con.setConnectTimeout(CONNECT_TIMEOUT_MILL);
                con.setReadTimeout(READ_TIMEOUT_MILL);


                var i = new java.io.InputStreamReader(con.getInputStream(), "UTF-8");
                var reader = new java.io.BufferedReader(i);

                // can't we just read to the end?
                var line = reader.readLine();
                while (line != null)
                {
                    w += line;
                    w += "\n";

                    line = reader.readLine();
                }
                reader.close();
            }
            catch
            {
                // oops
            }
            //Log.wtf("HttpURLConnection", w);

            if (w.Length > 0)
            {
                var value = w;
                var offset = 0;

                var i = ((java.lang.String)(object)value).indexOf("version=\"", offset) + "version=\"".Length;
                var j = ((java.lang.String)(object)value).indexOf("\"", i);

                var ii = ((java.lang.String)(object)value).indexOf("version=\"", j) + "version=\"".Length;
                var jj = ((java.lang.String)(object)value).indexOf("\"", ii);

                version = ((java.lang.String)(object)value).substring(ii, jj);


            }
            return version;
        }
Ejemplo n.º 3
0
        static string InternalGetSDKVersion()
        {
            var version = "";
            var w       = "";

            try
            {
                // by now we have webclient?
                // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201412/20141207
                var url = new java.net.URL(SDKVersionLocation);

                HttpURLConnection con = (HttpURLConnection)url.openConnection();

                int CONNECT_TIMEOUT_MILL = 2000;
                int READ_TIMEOUT_MILL    = 900;

                con.setConnectTimeout(CONNECT_TIMEOUT_MILL);
                con.setReadTimeout(READ_TIMEOUT_MILL);


                var i      = new java.io.InputStreamReader(con.getInputStream(), "UTF-8");
                var reader = new java.io.BufferedReader(i);

                // can't we just read to the end?
                var line = reader.readLine();
                while (line != null)
                {
                    w += line;
                    w += "\n";

                    line = reader.readLine();
                }
                reader.close();
            }
            catch
            {
                // oops
            }
            //Log.wtf("HttpURLConnection", w);

            if (w.Length > 0)
            {
                var value  = w;
                var offset = 0;

                var i = ((java.lang.String)(object) value).indexOf("version=\"", offset) + "version=\"".Length;
                var j = ((java.lang.String)(object) value).indexOf("\"", i);

                var ii = ((java.lang.String)(object) value).indexOf("version=\"", j) + "version=\"".Length;
                var jj = ((java.lang.String)(object) value).indexOf("\"", ii);

                version = ((java.lang.String)(object) value).substring(ii, jj);
            }
            return(version);
        }
Ejemplo n.º 4
0
 public override void run()
 {
     try
     {
         java.io.InputStreamReader isr = new java.io.InputStreamReader(_is);
         java.io.BufferedReader    br  = new java.io.BufferedReader(isr);
         String line = null;
         while ((line = br.readLine()) != null)
         {
             Debug.WriteLine(_type + ">" + line);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex);
     }
 }
        // 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

        }