예제 #1
0
		private void registerBroadcastReceiver()
		{
			IntentFilter filter = new IntentFilter();
			filter.addAction(SpassFingerprint.ACTION_FINGERPRINT_RESET);
			filter.addAction(SpassFingerprint.ACTION_FINGERPRINT_REMOVED);
			filter.addAction(SpassFingerprint.ACTION_FINGERPRINT_ADDED);
			mContext.registerReceiver(mPassReceiver, filter);
		};
예제 #2
0
        private void registerBroadcastReceiver()
        {
            IntentFilter filter = new IntentFilter();

            filter.addAction(SpassFingerprint.ACTION_FINGERPRINT_RESET);
            filter.addAction(SpassFingerprint.ACTION_FINGERPRINT_REMOVED);
            filter.addAction(SpassFingerprint.ACTION_FINGERPRINT_ADDED);
            mContext.registerReceiver(mPassReceiver, filter);
        };
            public virtual void onClick(DialogInterface dialog, int which)
            {
                MainActivity.mBixolonLabelPrinter.connect((UsbDevice)usbDevices.ToArray()[which]);

                // listen for new devices
                IntentFilter filter = new IntentFilter();

                filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
                filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
                context.registerReceiver(usbReceiver, filter);
            }
예제 #4
0
 private void registerReceiver()
 {
     if (!isReceiverRegistered)
     {
         IntentFilter intentFilter = new IntentFilter();
         intentFilter.addAction(ACTION_SET_GCM_TOKEN);
         intentFilter.addAction(ACTION_INCOMING_CALL);
         LocalBroadcastManager.getInstance(this).registerReceiver(voiceBroadcastReceiver, intentFilter);
         isReceiverRegistered = true;
     }
 }
		public override void onCreate(Bundle savedInstanceState)
		{
			base.onCreate(savedInstanceState);
			ContentView = R.layout.activity_nv_image;

			mImageView = (ImageView) findViewById(R.id.imageView1);
			mTextView = (TextView) findViewById(R.id.textView3);

			Button button = (Button) findViewById(R.id.button1);
			button.OnClickListener = this;
			button = (Button) findViewById(R.id.button2);
			button.OnClickListener = this;
			button = (Button) findViewById(R.id.button3);
			button.OnClickListener = this;
			button = (Button) findViewById(R.id.button4);
			button.OnClickListener = this;
			button = (Button) findViewById(R.id.button5);
			button.OnClickListener = this;

			mAdapter = new ArrayAdapter<string>(this, android.R.layout.simple_list_item_single_choice, mArrayList);

			mListView = (ListView) findViewById(R.id.listView1);
			mListView.Adapter = mAdapter;
			mListView.ChoiceMode = ListView.CHOICE_MODE_SINGLE;

			IntentFilter filter = new IntentFilter();
			filter.addAction(MainActivity.ACTION_GET_DEFINEED_NV_IMAGE_KEY_CODES);
			registerReceiver(mReceiver, filter);

			MainActivity.mBixolonPrinter.DefinedNvImageKeyCodes;
		}
        public override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);
            ContentView = R.layout.activity_nv_image;

            mImageView = (ImageView)findViewById(R.id.imageView1);
            mTextView  = (TextView)findViewById(R.id.textView3);

            Button button = (Button)findViewById(R.id.button1);

            button.OnClickListener = this;
            button = (Button)findViewById(R.id.button2);
            button.OnClickListener = this;
            button = (Button)findViewById(R.id.button3);
            button.OnClickListener = this;
            button = (Button)findViewById(R.id.button4);
            button.OnClickListener = this;
            button = (Button)findViewById(R.id.button5);
            button.OnClickListener = this;

            mAdapter = new ArrayAdapter <string>(this, android.R.layout.simple_list_item_single_choice, mArrayList);

            mListView            = (ListView)findViewById(R.id.listView1);
            mListView.Adapter    = mAdapter;
            mListView.ChoiceMode = ListView.CHOICE_MODE_SINGLE;

            IntentFilter filter = new IntentFilter();

            filter.addAction(MainActivity.ACTION_GET_DEFINEED_NV_IMAGE_KEY_CODES);
            registerReceiver(mReceiver, filter);

            MainActivity.mBixolonPrinter.DefinedNvImageKeyCodes;
        }
예제 #7
0
        public override void onCreate()
        {
            // TODO Auto-generated method stub
            IntentFilter filter = new IntentFilter();

            filter.addAction(Intent.ACTION_TIME_TICK);
            mContext.registerReceiver(mClockReceiver, filter);
        }
        private void registerBroadcastReceiver()
        {
            mBroadcastState = true;

            IntentFilter filter = new IntentFilter();

            filter.addAction(Intent.ACTION_PACKAGE_ADDED);
            filter.addDataScheme("package");

            this.registerReceiver(btReceiver, filter);
        }
        public static void startReceiver(Activity act)
        {
            activity = act;
            if (!registeredReceiver)
            {
                Log.d(TAG, "!!#######!! Registering console receiver");

                IntentFilter filter = new IntentFilter();
                filter.addAction(CONSOLE_INTENT);
                act.registerReceiver(receiver, filter);
                registeredReceiver = true;
            }
            else
            {
                Log.d(TAG, "!!!!!!!!!!! Already registered console receiver!");
            }
        }
예제 #10
0
        public override int onStartCommand(Intent value0, int value1, int value2)
        {
            var intentFilter = new IntentFilter();

            intentFilter.addAction(ACTION);
            registerReceiver(notifyServiceReceiver, intentFilter);


            // Send Notification
            var notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

            var myNotification = new Notification(
                android.R.drawable.star_on,
                //(CharSequence)(object)"Boot!!",
                "Boot!!",
                java.lang.System.currentTimeMillis()
                );

            var context = getApplicationContext();

            var myIntent = new Intent(Intent.ACTION_VIEW, android.net.Uri.parse("http://youtube.com"));

            var pendingIntent
                = PendingIntent.getActivity(getBaseContext(),
                                            0, myIntent,
                                            Intent.FLAG_ACTIVITY_NEW_TASK);

            myNotification.defaults |= Notification.DEFAULT_SOUND;
            myNotification.flags    |= Notification.FLAG_AUTO_CANCEL;
            myNotification.setLatestEventInfo(context,
                                              "Boot!!",
                                              "Proud to be a jsc developer :)",
                                              pendingIntent);
            notificationManager.notify(1, myNotification);


            return(base.onStartCommand(value0, value1, value2));
        }
        public override int onStartCommand(Intent value0, int value1, int value2)
        {
            IntentFilter intentFilter = new IntentFilter();

            intentFilter.addAction(ACTION);
            registerReceiver(notifyServiceReceiver, intentFilter);


            // Send Notification
            var notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

            var myNotification = new Notification(
                android.R.drawable.star_on,
                (CharSequence)(object)"Notification!",
                java.lang.System.currentTimeMillis()
                );

            Context context = getApplicationContext();

            Intent myIntent = new Intent(Intent.ACTION_VIEW, android.net.Uri.parse("http://www.jsc-solutions.net"));

            PendingIntent pendingIntent
                = PendingIntent.getActivity(getBaseContext(),
                                            0, myIntent,
                                            Intent.FLAG_ACTIVITY_NEW_TASK);

            myNotification.defaults |= Notification.DEFAULT_SOUND;
            myNotification.flags    |= Notification.FLAG_AUTO_CANCEL;
            myNotification.setLatestEventInfo(context,
                                              (CharSequence)(object)"The title that goes in the expanded entry.",
                                              (CharSequence)(object)"The text that goes in the expanded entry.",
                                              pendingIntent);
            notificationManager.notify(1, myNotification);


            return(base.onStartCommand(value0, value1, value2));
        }
예제 #12
0
			public virtual void onClick(DialogInterface dialog, int which)
			{
				MainActivity.mBixolonPrinter.connect((UsbDevice) usbDevices.ToArray()[which]);

				// listen for new devices
				IntentFilter filter = new IntentFilter();
				filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
				filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
				context.registerReceiver(usbReceiver, filter);
			}
예제 #13
0
        public override int onStartCommand(Intent value0, int value1, int value2)
        {
            #region Notify
            int counter = 0;
            Action <string, string, string> Notify =
                (Title, link, search) =>
            {
                counter++;

                var nm = (NotificationManager)this.getSystemService(Activity.NOTIFICATION_SERVICE);


                //var nn = new NotificationCompat
                // see http://developer.android.com/reference/android/app/Notification.html
                var notification = new Notification(
                    android.R.drawable.star_on,
                    Title,
                    java.lang.System.currentTimeMillis()
                    );

                // ToClass is like GetTypeInfo
                //var xmyIntent = new Intent(Intent.ACTION_VIEW, android.net.Uri.parse("http://youtube.com"));

                //http://stackoverflow.com/questions/9860456/search-a-specific-string-in-youtube-application-from-my-app

                // http://grokbase.com/t/gg/android-developers/123s02429a/use-marquee-on-notification-bar

                Intent xmyIntent = new Intent(Intent.ACTION_SEARCH);
                xmyIntent.setPackage("com.google.android.youtube");
                xmyIntent.putExtra("query", search);

                // https://code.google.com/p/android/issues/detail?id=82065
                // http://stackoverflow.com/questions/11939018/scrolling-text-in-notification
                xmyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                //startActivity(intent);

                //var xmyIntent = new Intent(Intent.ACTION_VIEW, android.net.Uri.parse(link));


                //[javac] W:\src\JVMCLRBroadcastLogger\__AndroidMulticast.java:165: error: bad operand type __Func_2< __f__AnonymousType_109_1_2<__NetworkInterface, Boolean>,__IEnumerable_1 < __UnicastIPAddressInformation >> for unary operator '!'
                //     [javac]             if (!__AndroidMulticast.CS___9__CachedAnonymousMethodDelegate10)
                //[javac] ^

                var xpendingIntent
                    = PendingIntent.getActivity(
                          getBaseContext(),
                          0,
                          xmyIntent,
                          Intent.FLAG_ACTIVITY_NEW_TASK);


                notification.setLatestEventInfo(
                    this,
                    Title,
                    Title,
                    xpendingIntent);


                // http://stackoverflow.com/questions/10402686/how-to-have-led-light-notification
                notification.defaults |= Notification.DEFAULT_VIBRATE;
                //notification.defaults |= Notification.DEFAULT_SOUND;
                //notification.defaults |= Notification.DEFAULT_LIGHTS;
                notification.defaults |= Notification.FLAG_SHOW_LIGHTS;


                //new Notification.BigTextStyle(

                // http://androiddrawableexplorer.appspot.com/
                nm.notify(counter, notification);

                //context.ToNotification(
                //      Title: Title,
                //      Content: Title,

                //      id: (int)java.lang.System.currentTimeMillis(),
                //        icon: android.R.drawable.star_on,
                //      uri: "http://my.jsc-solutions.net"
                //  );
            };
            #endregion

            var intentFilter = new IntentFilter();
            intentFilter.addAction(ACTION);
            registerReceiver(notifyServiceReceiver, intentFilter);

            //            0001 02000006 AndroidServiceUDPNotification.AndroidActivity::< module >.SHA1c9cbee88a1edabb97eb411ca262280fe2fa18dd1@229018826
            //{ OwnerMethod = Int32 onStartCommand(android.content.Intent, Int32, Int32), DeclaringType = AndroidServiceUDPNotification.Activities.NotifyService }
            //            {
            //                exc = System.Security.VerificationException: Operation could destabilize the runtime.
            //                 at System.RuntimeMethodHandle.GetMethodBody(IRuntimeMethodInfo method, RuntimeType declaringType)
            //               at System.Reflection.RuntimeMethodInfo.GetMethodBody()
            //               at jsc.ILBlock..ctor(MethodBase SourceMethod) in x:\jsc.internal.git\compiler\jsc\CodeModel\ILBlock.cs:line 349

            Notify("awaiting for tv...", "http://youtube.com", "music");

            // http://developer.android.com/reference/android/net/wifi/WifiManager.html
            // http://developer.android.com/reference/android/net/wifi/WifiManager.html#createMulticastLock(java.lang.String)
            ((WifiManager)this.getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "ApplicationActivity").acquire();
            ((WifiManager)this.getSystemService(Context.WIFI_SERVICE)).createMulticastLock("ApplicationActivity").acquire();

            new JVMCLRBroadcastLogger.__AndroidMulticast(
                AtData:
                xmlstring =>
            {
                // X:\jsc.svn\examples\javascript\chrome\apps\ChromeUDPNotification\ChromeUDPNotification\Application.cs

                var xml = XElement.Parse(xmlstring);

                if (xml.Value.StartsWith("Visit me at "))
                {
                    // what about android apps runnning on SSL?
                    // what about preview images?
                    // do we get localhost events too?

                    var n = xml.Attribute("n");

                    var uri  = "http://" + xml.Value.SkipUntilOrEmpty("Visit me at ");
                    var link = uri + "/results?search_query=" + n.Value;

                    Notify(n.Value, link, n.Value);
                }
            }
                );



            return(base.onStartCommand(value0, value1, value2));
        }
        // "x:\util\android-sdk-windows\platform-tools\adb.exe" connect 192.168.1.126:5555

        //  x:\util\android-sdk-windows\platform-tools\adb.exe logcat -s "xNativeActivity" "System.Console" "DEBUG"

        // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201505/20150513
        // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201505/20150531

        // 01. lets have our service think of a port, and send it back to activity at start. or save into file as cpu does it?
        // http://developer.android.com/reference/android/os/MemoryFile.html
        // http://stackoverflow.com/questions/19778196/class-memoryfile-of-any-use
        // http://stackoverflow.com/questions/15123402/share-memory-between-two-processes-in-dalvik
        // http://www.slideshare.net/tetsu.koba/interprocess-communication-of-android
        // http://www.codota.com/android/scenarios/52fcbca7da0a12229fc989b1/android.os.MemoryFile?tag=dragonfly
        // https://groups.google.com/forum/#!topic/android-developers/r-oqeI7MlJg
        // http://stackoverflow.com/questions/19778196/class-memoryfile-of-any-use
        // https://vec.io/posts/andriod-ipc-shared-memory-with-ashmem-memoryfile-and-binder
        // http://notjustburritos.tumblr.com/post/21442138796/an-introduction-to-android-shared-memory
        // https://developer.android.com/training/articles/memory.html
        // http://www.slideshare.net/jserv/android-ipc-mechanism

        //Action AtActivityResult;

        //protected override void onActivityResult(int arg0, int arg1, Intent arg2)
        //{
        //    base.onActivityResult(arg0, arg1, arg2);

        //    if (AtActivityResult != null)
        //        AtActivityResult();
        //}



        //        I/ActivityManager(  475): Killing 7649:AndroidMultiProcTCPServerAsync.Activities/u0a49 (adj 9): remove task
        //I/ActivityManager(  475): Killing 7627:AndroidMultiProcTCPServerAsync.Activities:gateway7/u0a49 (adj 5): remove task
        //I/ActivityManager(  475): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.l
        //W/ActivityManager(  475): Scheduling restart of crashed service AndroidMultiProcTCPServerAsync.Activities/.GatewayService in 16000ms

        //protected override void onPause()
        //{
        //    Console.WriteLine("enter onPause, finishAndRemoveTask");


        //    // not called on back button?
        //    // keep service running, remove activity
        //    this.finishAndRemoveTask();

        //    base.onPause();



        //}

        protected override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);

            // fill the button
            ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);


            this.setContentView(sv);

            var activity = this;


            new Button(activity).WithText("is the service already running?").AttachTo(ll);

            var m = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);
            // why limit?
            var s = m.getRunningServices(0xffff);

            var a = Enumerable.FirstOrDefault(
                from i in Enumerable.Range(0, s.size())
                let rsi                   = (android.app.ActivityManager.RunningServiceInfo)s.get(i)
                                   let cn = rsi.service.getClassName()
                                            where cn == typeof(GatewayService).FullName
                                            select new { i, rsi, cn }
                );

            if (a == null)
            {
                new Button(activity).WithText("start service").AttachTo(ll).AtClick(
                    delegate
                {
                    // start the service unless already running?
                    var intent = new Intent(this.getApplicationContext(), typeof(GatewayService).ToClass());
                    // if the user can swipe us away service is restarted?
                    this.getApplicationContext().startService(intent);
                }
                    );
            }
            else
            {
            }


            // whats the port?

            new Button(activity).WithText("which port are we on? " + new { a }).AttachTo(ll).AtClick(
                delegate
            {
                var aa = default(AsyncReplyReceiver);

                aa = new AsyncReplyReceiver
                {
                    AtReceive = (cc, ii) =>
                    {
                        Console.WriteLine("ui now has the port...");
                        this.unregisterReceiver(aa);


                        var host = ii.getStringExtra("host");
                        var port = ii.getIntExtra("port", 0);

                        new Button(activity).WithText("open " + host + ":" + port).AttachTo(ll).AtClick(
                            delegate
                        {
                            var href =
                                "http://" + host + ":" + port;

                            Console.WriteLine(
                                href
                                );



                            //this.runOnUiThread(
                            //    delegate
                            //    {
                            var i = new Intent(Intent.ACTION_VIEW,
                                               android.net.Uri.parse(href)
                                               );

                            // http://vaibhavsarode.wordpress.com/2012/05/14/creating-our-own-activity-launcher-chooser-dialog-android-launcher-selection-dialog/
                            var ic = Intent.createChooser(i, href);


                            this.startActivity(ic);
                            //    }
                            //);
                        }
                            );
                    }
                };

                var intentFilter = new IntentFilter();
                intentFilter.addAction(GatewayService.ACTION + "reply");
                this.registerReceiver(aa, intentFilter);


                var intent = new Intent();
                intent.setAction(GatewayService.ACTION);
                intent.putExtra("whats my port", "?");
                this.sendBroadcast(intent);
            }
                );



            new Button(this).WithText("exit").AttachTo(ll).AtClick(
                delegate
            {
                // will it be logged?
                System.Environment.Exit(13);

                // application still visible in tasks?
            }
                );

            new Button(this).WithText("finish").AttachTo(ll).AtClick(
                delegate
            {
                //this.finishAndRemoveTask();
                this.finish();

                // will it be logged?
                //System.Environment.Exit(13);

                // application still visible in tasks?
            }
                );

            new Button(this).WithText("finishAndRemoveTask").AttachTo(ll).AtClick(
                delegate
            {
                this.finishAndRemoveTask();
                //this.finish();

                // will it be logged?
                //System.Environment.Exit(13);

                // application still visible in tasks?
            }
                );


            //            [javac] W:\src\AndroidMultiProcTCPServerAsync\Activities\ApplicationActivity.java:56: error: unreported exception IOException; must be caught or declared to be thrown
            //[javac]         class22.m = new MemoryFile("foo0", 100);

            //// ipc memory referenced
            //var m = default(MemoryFile);

            //try
            //{
            //    m = new MemoryFile("foo0", 100);
            //}
            //catch { throw; }


            // MemoryFile not available yet. bypass to NDK? workaround to filesystem?

            // E/AndroidRuntime(28716): Caused by: android.system.ErrnoException: open failed: EROFS (Read-only file system)

            // http://developer.android.com/training/basics/data-storage/files.html

            //  File.WriteAllText(this.getFilesDir().getAbsolutePath() + "/MemoryFile-foo0", "awaiting...");



            //  new Button(activity).WithText("Next " +

            //      File.ReadAllText(this.getFilesDir().getAbsolutePath() + "/MemoryFile-foo0")

            //      ).AttachTo(ll).AtClick(
            //      button =>
            //      {
            //          Intent intent = new Intent(activity, typeof(SecondaryActivity).ToClass());
            //          intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

            //          // share scope
            //          var myPid = android.os.Process.myPid();
            //          intent.putExtra("_item", "hello from " + new { myPid });

            //          //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

            //          //new Button(activity).WithText("read").AttachTo(ll).AtClick(
            //          //      button2 =>
            //          //      {
            //          //          var m2 = default(MemoryFile);

            //          //          try
            //          //          {
            //          //              m2 = new MemoryFile("foo0", 100);
            //          //          }
            //          //          catch { throw; }


            //          //          var pos = 0;

            //          //          //var __out = new __NetworkStream { InternalOutputStream = m.getOutputStream() };
            //          //          var __in = new __NetworkStream { InternalInputStream = m2.getInputStream() };

            //          //          // block the ui?

            //          //          var ipcByte = 0;
            //          //          while (ipcByte == 0)
            //          //          {
            //          //              ipcByte = __in.ReadByte();
            //          //              button2.WithText(new { ipcByte, pos }.ToString());
            //          //              pos++;
            //          //          }
            //          //      }
            //          //  );

            //          AtActivityResult +=
            //              delegate
            //              {
            //                  // if we read too early we get all zeros..

            //                  //var pos = 0;

            //                  ////var __out = new __NetworkStream { InternalOutputStream = m.getOutputStream() };
            //                  //var __in = new __NetworkStream { InternalInputStream = m.getInputStream() };

            //                  //// block the ui?

            //                  //var ipcByte = 0;
            //                  //while (ipcByte == 0)
            //                  //{
            //                  //    ipcByte = __in.ReadByte();
            //                  //    button.WithText(new { ipcByte, pos }.ToString());
            //                  //    pos++;
            //                  //}

            //                  button.WithText(
            //                   File.ReadAllText(this.getFilesDir().getAbsolutePath() + "/MemoryFile-foo0")
            //                 );

            //              };

            //          // cached backgroun process?
            //          // switching to another process.. easy...
            //          //activity.startActivity(intent);
            //          activity.startActivityForResult(intent, requestCode: 0x14);

            //      }
            //);

            //  //var s = new SemaphoreSlim(0);

            //  ////java.lang.Object, rt
            //  ////enter async { ManagedThreadId = 1 }
            //  ////awaiting for SemaphoreSlim{ ManagedThreadId = 1 }
            //  ////after delay{ ManagedThreadId = 8 }
            //  ////http://127.0.0.1:8080
            //  ////{ fileName = http://127.0.0.1:8080 }
            //  ////enter catch { mname = <0032> nop.try } ClauseCatchLocal:
            //  ////{ Message = , StackTrace = java.lang.RuntimeException
            //  ////        at ScriptCoreLibJava.BCLImplementation.System.Net.Sockets.__TcpListener.AcceptTcpClientAsync(__TcpListener.java:131)

            //  //new { }.With(
            //  //    async delegate
            //  //    {
            //  //        //System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
            //  //        //enter async { ManagedThreadId = 1 }
            //  //        //awaiting for SemaphoreSlim{ ManagedThreadId = 1 }
            //  //        //after delay{ ManagedThreadId = 4 }
            //  //        //http://127.0.0.1:8080
            //  //        //awaiting for SemaphoreSlim. done.{ ManagedThreadId = 1 }
            //  //        //--
            //  //        //accept { c = System.Net.Sockets.TcpClient, ManagedThreadId = 6 }
            //  //        //System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
            //  //        //accept { c = System.Net.Sockets.TcpClient, ManagedThreadId = 8 }
            //  //        //{ ManagedThreadId = 6, input = GET / HTTP/1.1



            //  //        // jump back to main thread..
            //  //        s.Release();
            //  //    }
            //  //);
        }
        // gateway service process/ event thread / async enabled?
        public override int onStartCommand(Intent value0, int flags, int startId)
        {
            // Options that have been set in the service declaration in the manifest.
            // http://developer.android.com/reference/android/content/pm/ServiceInfo.html#FLAG_STOP_WITH_TASK

            Console.WriteLine("enter onStartCommand " + new { flags, startId });



            // until wifi changes?
            var xipv4 =
                //from n in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
                from n in AllNetworkInterfaces
                let IPProperties                 = n.GetIPProperties()
                                           let c = IPProperties.UnicastAddresses.Count
                                                   from i in Enumerable.Range(0, c)
                                                   let ip = IPProperties.UnicastAddresses[i]


                                                            where ip.Address.AddressFamily == AddressFamily.InterNetwork
                                                            //let loop = IPAddress.Loopback == ip.Address
                                                            let loop = IPAddress.IsLoopback(ip.Address)

                                                                       orderby loop
                                                                       select new { n, ip, loop, ip.Address };

            //I/System.Console(20546): 5042:0001 { n = ScriptCoreLibJava.BCLImplementation.System.Net.NetworkInformation.__NetworkInterface@37e1894a, ip = { Address = 192.168.1.126 }, loop = false, Address = 192.168.1.126 }
            //I/System.Console(20546): 5042:0001 { n = ScriptCoreLibJava.BCLImplementation.System.Net.NetworkInformation.__NetworkInterface@3c1830bb, ip = { Address = 127.0.0.1 }, loop = true, Address = 127.0.0.1 }

            xipv4.WithEach(
                Console.WriteLine
                );

            var BestGuessHost = xipv4.FirstOrDefault();

            Console.WriteLine(" " + new { BestGuessHost });


            //var port = new Random().Next(8000, 30000);

            // cached by cloudflare?
            //var port = 80;
            var port = 8080;
            // https://github.com/NanoHttpd/nanohttpd/blob/master/core/src/main/java/fi/iki/elonen/NanoHTTPD.java

            var notifyServiceReceiver = new AsyncReplyReceiver
            {
                AtReceive = (cc, ii) =>
                {
                    Console.WriteLine("enter onReceive");

                    //android.content.IntentFilter
                    //android.content.Intent.ACTION_BOOT_COMPLETED
                    int rqs = ii.getIntExtra("RQS", 0);

                    if (rqs == RQS_STOP_SERVICE)
                    {
                        this.stopSelf();
                    }

                    if (ii.hasExtra("whats my port"))
                    {
                        // how do we reply?
                        // sharedmemory implementation is missing and useless

                        xipv4.WithEach(
                            Console.WriteLine
                            );

                        var intent = new Intent();
                        //intent.putExtra("host", BestGuessHost.Address.ToString());

                        // did we switch networks?
                        intent.putExtra("host", xipv4.FirstOrDefault().ToString());
                        intent.putExtra("port", port);
                        intent.setAction(GatewayService.ACTION + "reply");
                        this.sendBroadcast(intent);
                    }
                }
            };



            #region AtDestroy
            this.AtDestroy = delegate
            {
                Console.WriteLine("enter AtDestroy");

                this.unregisterReceiver(notifyServiceReceiver);
                //            I/System.Console( 8080): onDestroy { xmyPid = 8080 }
                //I/art     ( 8080): System.exit called, status: 42

                var xmyPid = android.os.Process.myPid();
                Console.WriteLine("onDestroy " + new { xmyPid });

                System.Environment.Exit(42);
            };
            #endregion


            //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 2, Name = ip6tnl0, Description = ip6tnl0, SupportsMulticast = false, InetAddressesString =  }
            //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 2, Name = rmnet4, Description = rmnet4, SupportsMulticast = true, InetAddressesString =  }
            //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 2, Name = rmnet2, Description = rmnet2, SupportsMulticast = true, InetAddressesString =  }
            //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 2, Name = rmnet3, Description = rmnet3, SupportsMulticast = true, InetAddressesString =  }
            //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 2, Name = rmnet7, Description = rmnet7, SupportsMulticast = true, InetAddressesString =  }
            //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 2, Name = rmnet5, Description = rmnet5, SupportsMulticast = true, InetAddressesString =  }
            //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 2, Name = rmnet6, Description = rmnet6, SupportsMulticast = true, InetAddressesString =  }
            //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 2, Name = rmnet1, Description = rmnet1, SupportsMulticast = true, InetAddressesString =  }
            //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 2, Name = rmnet0, Description = rmnet0, SupportsMulticast = true, InetAddressesString =  }

            //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 1, Name = lo, Description = lo, SupportsMulticast = false, InetAddressesString = , ::1%1, 127.0.0.1 }
            //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 2, Name = sit0, Description = sit0, SupportsMulticast = false, InetAddressesString =  }
            //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 1, Name = p2p0, Description = p2p0, SupportsMulticast = true, InetAddressesString = , fe80::e850:8bff:fe7d:277c%p2p0 }
            //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 1, Name = wlan0, Description = wlan0, SupportsMulticast = true, InetAddressesString = , 2001:7d0:8414:3001:ea50:8bff:fe7d:277c%13, fe80::ea50:8bff:fe7d:277c%wlan0, 2001:7d0:8414:3001:b421:4790:ede8:826c%13, 192.168.1.126 }



            //I/System.Console(15259): 3b9b:0001 { OperationalStatus = 1, Name = lo, Description = lo, SupportsMulticast = false, InetAddressesString = , ::1%1, 127.0.0.1 }
            //I/System.Console(15259): 3b9b:0001 { OperationalStatus = 2, Name = dummy0, Description = dummy0, SupportsMulticast = false, InetAddressesString =  }
            //I/System.Console(15259): 3b9b:0001 { OperationalStatus = 2, Name = sit0, Description = sit0, SupportsMulticast = false, InetAddressesString =  }
            //I/System.Console(15259): 3b9b:0001 { OperationalStatus = 2, Name = ip6tnl0, Description = ip6tnl0, SupportsMulticast = false, InetAddressesString =  }
            //I/System.Console(15259): 3b9b:0001 { OperationalStatus = 1, Name = p2p0, Description = p2p0, SupportsMulticast = true, InetAddressesString = , fe80::10bf:48ff:febe:6b7d%p2p0 }
            //I/System.Console(15259): 3b9b:0001 { OperationalStatus = 1, Name = wlan0, Description = wlan0, SupportsMulticast = true, InetAddressesString = , 2001:7d0:8414:3001:a06f:6dfe:8dfc:42b8%6, 2001:7d0:8414:3001:12bf:48ff:febe:6b7d%6, fe80::12bf:48ff:febe:6b7d%wlan0, 192.168.1.211 }

            // I/System.Console(11408): 2c90:0001 { OperationalStatus = 1, Name = rmnet0, Description = rmnet0, SupportsMulticast = true, InetAddressesString = , 83.187.193.24 }

            //Implementation not found for type import :
            //type: System.Net.NetworkInformation.UnicastIPAddressInformationCollection
            //method: System.Net.NetworkInformation.UnicastIPAddressInformation get_Item(Int32)
            //Did you forget to add the [Script] attribute?
            //Please double check the signature!



            // http://stackoverflow.com/questions/14182014/android-oncreate-or-onstartcommand-for-starting-service



            var myPid = android.os.Process.myPid();

            var intentFilter = new IntentFilter();
            intentFilter.addAction(ACTION);
            registerReceiver(notifyServiceReceiver, intentFilter);


            Func <TcpListener> ctor = delegate
            {
                TcpListener x = null;
                try
                {
                    Console.WriteLine("774 TcpListener " + new { port });
                    x = new TcpListener(IPAddress.Any, port);
                    Console.WriteLine("776 TcpListener ");

                    // signal UI service is yet again available
                    //Console.WriteLine("before Start ");

                    // I/System.Console(25817): 64d9:0001 { err = java.lang.RuntimeException: bind failed: EACCES (Permission denied) }

                    x.Start();

                    Console.WriteLine("782 TcpListener ");
                }
                catch (Exception err)
                {
                    Console.WriteLine(new { err });
                    System.Environment.Exit(42);
                }

                return(x);
            };



            #region TcpListener
            new { }.With(
                async delegate
            {
                //var l = new TcpListener(IPAddress.Any, port);
                var l = ctor();



                var href =
                    "http://127.0.0.1:" + port;

                Console.WriteLine(
                    href
                    );

                while (true)
                {
                    //Console.WriteLine("before AcceptTcpClientAsync ");

                    var c = await l.AcceptTcpClientAsync();

                    // time to do firewall or security?

                    //Console.WriteLine("before yield " + new { c });

                    yield(c);
                    //Console.WriteLine("after yield " + new { c });
                }
            }
                );
            #endregion


            var onStartCommand_status = base.onStartCommand(value0, flags, startId);

            Console.WriteLine("exit onStartCommand " + new { onStartCommand_status });

            // I/System.Console( 9005): 232d:0001 exit onStartCommand { onStartCommand_status = 1 }

            return(onStartCommand_status);
        }
예제 #16
0
        // inspired by http://baroqueworksdev.blogspot.com/2012/09/how-to-handle-screen-onoff-and-keygurad.html



        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);

            ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);


            this.setContentView(sv);


            new Button(this).WithText("register").AttachTo(ll).AtClick(
                btn =>
            {
                btn.setEnabled(false);

                // get KeyGuardManager
                var mKeyguard = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);

                var mReceiver = new MyBroadcastReceiver();

                mReceiver.AtReceive +=
                    (Context context, Intent intent) =>
                {
                    #region Notify
                    int counter            = 0;
                    Action <string> Notify =
                        Title =>
                    {
                        counter++;

                        var nm = (NotificationManager)this.getSystemService(Activity.NOTIFICATION_SERVICE);

                        // see http://developer.android.com/reference/android/app/Notification.html
                        var notification = new Notification(
                            android.R.drawable.star_on,
                            Title,
                            java.lang.System.currentTimeMillis()
                            );

                        // ToClass is like GetTypeInfo
                        var notificationIntent = new Intent(this, typeof(AndroidUnlockActivity).ToClass());
                        var contentIntent      = PendingIntent.getActivity(this, 0, notificationIntent, 0);


                        notification.setLatestEventInfo(
                            this,
                            Title,
                            "",
                            contentIntent);

                        // http://stackoverflow.com/questions/10402686/how-to-have-led-light-notification
                        notification.defaults |= Notification.DEFAULT_VIBRATE;
                        notification.defaults |= Notification.DEFAULT_SOUND;
                        //notification.defaults |= Notification.DEFAULT_LIGHTS;
                        notification.defaults |= Notification.FLAG_SHOW_LIGHTS;
                        // http://androiddrawableexplorer.appspot.com/
                        nm.notify(counter, notification);

                        //context.ToNotification(
                        //      Title: Title,
                        //      Content: Title,

                        //      id: (int)java.lang.System.currentTimeMillis(),
                        //        icon: android.R.drawable.star_on,
                        //      uri: "http://my.jsc-solutions.net"
                        //  );
                    };
                    #endregion

                    var action = intent.getAction();
                    if (action == Intent.ACTION_SCREEN_OFF)
                    {
                        // Screen is off
                        Notify("ACTION_SCREEN_OFF");
                    }
                    else if (action == Intent.ACTION_SCREEN_ON)
                    {
                        // Intent.ACTION_USER_PRESENT will be broadcast when the screen
                        // is
                        // unlocked.

                        // if API Level 16

                        /*
                         * if(mKeyguard.isKeyguardLocked()){ // the keyguard is
                         * currently locked. Log.e("","ACTION_SCREEN_ON : locked"); }
                         */
                        if (mKeyguard.inKeyguardRestrictedInputMode())
                        {
                            // the keyguard is currently locked.
                            Notify("ACTION_SCREEN_ON : locked");
                        }
                        else
                        {
                            // unlocked
                            Notify("ACTION_SCREEN_ON : unlocked");
                        }
                    }
                    else if (action == Intent.ACTION_USER_PRESENT)
                    {
                        // The user has unlocked the screen. Enabled!
                        Notify("ACTION_USER_PRESENT");
                    }
                };


                // IntetFilter with Action
                IntentFilter intentFilter = new IntentFilter();
                intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
                intentFilter.addAction(Intent.ACTION_SCREEN_ON);
                intentFilter.addAction(Intent.ACTION_USER_PRESENT);    // Keyguard is GONE

                // register BroadcastReceiver and IntentFilter
                registerReceiver(mReceiver, intentFilter);
            }
                );

            //this.ShowToast("http://jsc-solutions.net");
        }
		public override void onCreate()
		{
			// TODO Auto-generated method stub
			IntentFilter filter = new IntentFilter();
			filter.addAction(Intent.ACTION_TIME_TICK);
			mContext.registerReceiver(mClockReceiver, filter);
		}
예제 #18
0
		private void registerBroadcastReceiver()
		{
			mBroadcastState = true;

			IntentFilter filter = new IntentFilter();

			filter.addAction(Intent.ACTION_PACKAGE_ADDED);
			filter.addDataScheme("package");

			this.registerReceiver(btReceiver, filter);
		}
예제 #19
0
        public override int onStartCommand(Intent value0, int value1, int value2)
        {
            // http://stackoverflow.com/questions/14182014/android-oncreate-or-onstartcommand-for-starting-service


            new Thread(
                delegate()
            {
                var sw = Stopwatch.StartNew();

                while (true)
                {
                    var xmyPid = android.os.Process.myPid();

                    // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150612/ovroculus360photoshud
                    // cpu
                    Console.WriteLine(new { xmyPid, Thread.CurrentThread.ManagedThreadId, sw });

                    // "x:\util\android-sdk-windows\platform-tools\adb.exe" uninstall AndroidBootServiceNotificationActivity.Activities
                    Thread.Sleep(1000);
                }
            }
                )
            {
                Name = "namedthread1"
            }.Start();

            var myPid = android.os.Process.myPid();

            var intentFilter = new IntentFilter();

            intentFilter.addAction(ACTION);
            registerReceiver(notifyServiceReceiver, intentFilter);


            #region Send Notification
            var notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

            var myNotification = new Notification(
                android.R.drawable.star_on,
                //(CharSequence)(object)"Boot!!",
                "Boot!!" + new { myPid },

                when: 0

                //java.lang.System.currentTimeMillis()
                );

            var context = getApplicationContext();

            var myIntent = new Intent(Intent.ACTION_VIEW, android.net.Uri.parse("http://youtube.com"));

            var pendingIntent
                = PendingIntent.getActivity(getBaseContext(),
                                            0, myIntent,
                                            Intent.FLAG_ACTIVITY_NEW_TASK);
            myNotification.defaults |= Notification.DEFAULT_SOUND;
            myNotification.flags    |= Notification.FLAG_AUTO_CANCEL;
            myNotification.setLatestEventInfo(context,
                                              "Boot!!" + new { myPid },
                                              "Proud to be a jsc developer :)",
                                              pendingIntent);
            notificationManager.notify(1, myNotification);
            #endregion



            return(base.onStartCommand(value0, value1, value2));
        }