Наследование: java.lang.Object, android.os.Parcelable, java.lang.Cloneable
Пример #1
0
        // why we need this?
        protected override void onNewIntent(android.content.Intent value)
        {
            base.onNewIntent(value);
            var DataString = value.getDataString();

            Console.WriteLine("exit onNewIntent " + new { DataString });

            // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150704/pui_global_menu
        }
Пример #2
0
		protected override void onListItemClick (ListView l, View v, int position, long id)
		{
			var item = (Map<String,Object>)l.getItemAtPosition (position);
			var type = (Type)item.get("type");

			var intent = new Intent (this, typeof (TestActivity));
			intent.putExtra ("type", type.FullName);
			startActivity (intent);
		}
Пример #3
0
        // r(20814): /data/local/tmp/AndroidNFCBroadcastReceiver.Activities-debug.apk (at Binary XML file line #16): 
        // <receiver> does not have valid android:name
        // Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]
        // http://stackoverflow.com/questions/16645632/programmatic-vs-static-broadcast-recievers-in-android

        // http://stackoverflow.com/questions/4853622/android-nfc-tag-received-with-broadcastreceiver
        // http://stackoverflow.com/questions/6829655/nfc-broadcast-problem
        // You can't capture those intents with a BroadcastReceiver, because only Activities 
        // can receive NFC intents. You can find more information about it in the NFC guide.
        public override void onReceive(Context arg0, Intent arg1)
        {
            var context = ThreadLocalContextReference.CurrentContext;

            var action = arg1.getAction();


            Console.WriteLine("AtDiscovered " + new { action });
        }
        // http://stackoverflow.com/questions/6274141/trigger-background-service-at-a-specific-time-in-android
        // http://stackoverflow.com/questions/7144908/how-is-an-intent-service-declared-in-the-android-manifest
        // http://developer.android.com/guide/topics/manifest/service-element.html


        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            // http://developer.android.com/guide/topics/ui/notifiers/notifications.html

            base.onCreate(savedInstanceState);

            ScrollView sv = new ScrollView(this);

            LinearLayout ll = new LinearLayout(this);

            ll.setOrientation(LinearLayout.VERTICAL);

            sv.addView(ll);

            #region startservice
            var startservice = new Button(this);
            startservice.setText("Start Service to send Notification");
            startservice.AtClick(
               delegate
               {
                   this.ShowToast("startservice_onclick");

                   var intent = new Intent(this, typeof(NotifyService).ToClass());

                   this.startService(intent);
               }
            );
            ll.addView(startservice);
            #endregion

            #region stopservice
            var stopservice = new Button(this);
            stopservice.setText("Stop Service");
            stopservice.AtClick(
                delegate
                {
                    this.ShowToast("stopservice_onclick");

                    Intent intent = new Intent();
                    intent.setAction(NotifyService.ACTION);
                    intent.putExtra("RQS", NotifyService.RQS_STOP_SERVICE);
                    this.sendBroadcast(intent);

                }
            );
            ll.addView(stopservice);
            #endregion

            this.setContentView(sv);

            this.ShowToast("http://jsc-solutions.net");


        }
        /// <summary>
        /// This Method is a javascript callable method.
        /// </summary>
        /// <param name="e">A parameter from javascript.</param>
        /// <param name="y">A callback to javascript.</param>
        public void WebMethod2(string e, Action<string> y)
        {
            // https://code.google.com/p/android/issues/detail?id=14869
            // seems to exist!
            var VMRuntime = Type.GetType("dalvik.system.VMRuntime");

            e += new { VMRuntime };

            Console.WriteLine(new { VMRuntime });



            var c = ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext;

            var intent = new Intent(c, typeof(foo.NotifyService).ToClass());

            intent.putExtra("data0", e);

            c.startService(intent);

            // http://stackoverflow.com/questions/7598835/alternative-of-vmruntime-getruntime-setminimumheapsize-in-gingerbread


            if (VMRuntime != null)
            {

                //Implementation not found for type import :
                //type: System.Type
                //method: System.Reflection.MethodInfo GetMethod(System.String)
                //Did you forget to add the [Script] attribute?
                //Please double check the signature!


                //var VMRuntime_getRuntime = VMRuntime.GetMethod("getRuntime");
                var VMRuntime_getRuntime = VMRuntime.GetMethod("getRuntime", new Type[0]);

                Console.WriteLine(new { VMRuntime_getRuntime });

                // https://android.googlesource.com/platform/libcore/+/9edf43dfcc35c761d97eb9156ac4254152ddbc55/libdvm/src/main/java/dalvik/system/VMRuntime.java
                var r = VMRuntime_getRuntime.Invoke(null, new object[0]);

                Console.WriteLine(new { r });

                //I/System.Console( 8079): { VMRuntime = dalvik.system.VMRuntime }
                //I/System.Console( 8079): { VMRuntime_getRuntime = dalvik.system.VMRuntime getRuntime() }
                //I/System.Console( 8079): { r = dalvik.system.VMRuntime@41764740 }

            }


            // Send it back to the caller.
            y(e);
        }
Пример #6
0
		public void onMonkeySelected (Monkey monkey)
		{
			var image = (MonkeyImage)getFragmentManager ().findFragmentById (R.id.image_fragment);
			if (image != null)
				image.setMonkey (monkey);
			else {
				Intent intent = new Intent (this, typeof (ImageActivity));
				intent.putExtra (EXTRA_TITLE, monkey.Name);
				intent.putExtra (EXTRA_RESOURCE, monkey.ResourceId);
				startActivityForResult (intent, 1);
			}
		}
Пример #7
0
        public override void onReceive(Context arg0, Intent arg1)
        {
            var context = ThreadLocalContextReference.CurrentContext;

            var uri = arg1.getData();

            var packageName = uri.getSchemeSpecificPart();

            Console.WriteLine("AtInstall " + new { packageName });
            // I/System.Console( 3900): AtInstall { arg1 = Intent { act=android.intent.action.PACKAGE_REPLACED dat=package:NASDAQSNA.Activities flg=0x8000010 cmp=ReinstallNotification.Activities/.AtInstall (has extras) }, packageName = NASDAQSNA.Activities }

            History.Add(packageName);

        }
 public override void onReceive(Context arg0, Intent intent)
 {
     Log.d(TAG, "!@#!@ConsoleReceiver action:" + intent);
     if (intent.getAction() == CONSOLE_INTENT)
     {
         // Unity apps will not have a VrActivity, so they can only use console functions that are ok
         // with a NULL appPtr.
         if (activity is VrActivity)
         {
             nativeConsoleCommand(((VrActivity)activity).appPtr, intent.getStringExtra(CONSOLE_STRING_EXTRA));
         }
         else
         {
             nativeConsoleCommand(((long)0), intent.getStringExtra(CONSOLE_STRING_EXTRA));
         }
     }
 }
Пример #9
0
		public override Intent getLaunchIntentForPackage (string packageName)
		{
			if (!loaded_packages.ContainsKey (packageName))
				return null;

			XobotPackageInfo info = loaded_packages [packageName];

			if (info.Info.applicationInfo == null)
				throw new RuntimeException ("Cannot get ApplicationInfo from package.");
			if (info.Info.activities.Length < 1)
				throw new RuntimeException ("Package does not contain any Activity.");

			ActivityInfo ai = info.Info.activities [0];
			ai.applicationInfo.uid = android.os.Process.SYSTEM_UID;

			Intent intent = new Intent (Intent.ACTION_MAIN);
			intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
			intent.setPackage (packageName);
			intent.setClassName (info.Info.packageName, ai.name);

			return intent;
		}
        // jsc: seems like we need atleast one in and one out string :)
        public void CreateEvent(string Title, string Location, string Description, Action<string> y)
        {
            // http://developer.android.com/reference/android/provider/CalendarContract.EventsColumns.html#DESCRIPTION
            Console.WriteLine("CreateEvent " + new { Title, Location, Description });

            Intent calIntent = new Intent(Intent.ACTION_INSERT);

            // when one opens browser in android calendar stays hidden..
            // http://stackoverflow.com/questions/2232238/how-to-bring-an-activity-to-foreground-top-of-stack
            //calIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

            calIntent.setType("vnd.android.cursor.item/event");
            calIntent.putExtra("title", Title);
            calIntent.putExtra("eventLocation", Location);
            calIntent.putExtra("description", Description);

            GregorianCalendar calDate = new GregorianCalendar(2012, 7, 15);
            calIntent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);
            calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
                 calDate.getTimeInMillis());
            calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
                 calDate.getTimeInMillis());



            calIntent.putExtra("accessLevel", 0x00000002);
            calIntent.putExtra("availability", 0x00000000);

            calIntent.putExtra("rrule", "FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH");


            // well spawn another activity/thread
            ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext.startActivity(calIntent);

            y("");
        
        }
Пример #11
0
        public static void StartPendingAlarm(this Context that, Class IntentClass, long delay = 1000  * 5, long repeat = 1000 * 25)
        {
            that.CancelPendingAlarm(IntentClass);

            var myIntent = new Intent(that, IntentClass);
            var pendingIntent = PendingIntent.getService(that, 0, myIntent, 0);

            AlarmManager alarmManager = (AlarmManager)that.getSystemService(Context.ALARM_SERVICE);


            if (repeat > 0)
            {
                alarmManager.setInexactRepeating(
                      AlarmManager.RTC,
                      delay,
                      repeat,
                      pendingIntent
                  );
            }
            else
            {
                alarmManager.set(AlarmManager.RTC, delay, pendingIntent);
            }
        }
Пример #12
0
        public static void CancelPendingAlarm(this Context that, Class IntentClass)
        {

            // http://stackoverflow.com/questions/6522792/get-list-of-active-pendingintents-in-alarmmanager
            var myIntent = new Intent(that, IntentClass);
            var pendingIntent = PendingIntent.getService(that, 0, myIntent, 0);


            AlarmManager alarmManager = (AlarmManager)that.getSystemService(Context.ALARM_SERVICE);
            alarmManager.cancel(pendingIntent);
        }
Пример #13
0
        public static void ToNotification(this Context that, string Title, string Content, int id, int icon = 0, string uri = "http://www.jsc-solutions.net")
        {
            // Send Notification
            var notificationManager = (NotificationManager)that.getSystemService(Context.NOTIFICATION_SERVICE);

            var w = Title + " ";
            w += Content;

            if (icon == 0)
                icon = android.R.drawable.star_on;

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

            Context context = that.getApplicationContext();

            // ah. c# dynamic for android versions :)

            //#region Notification.largeIcon
            //try
            //{
            //    var largeIcon = AbstractNotifyService.NotificationClass.getField("largeIcon");

            //    if (largeIcon != null)
            //    {
            //        BitmapFactory.Options options = new BitmapFactory.Options();
            //        options.inScaled = false;	// No pre-scaling

            //        // Read in the resource
            //        Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.white_jsc, options);

            //        largeIcon.set(myNotification, bitmap);
            //    }
            //}
            //catch
            //{ }
            //#endregion


            Intent myIntent = new Intent(Intent.ACTION_VIEW, android.net.Uri.parse(uri));

            var BaseContext = that;

            var IsContextWrapper = that is ContextWrapper;
            if (IsContextWrapper)
                BaseContext = ((ContextWrapper)that).getBaseContext();

            PendingIntent pendingIntent
                //= PendingIntent.getActivity(that.getBaseContext(),
              = PendingIntent.getActivity(BaseContext,
                0, myIntent,
                Intent.FLAG_ACTIVITY_NEW_TASK);
            myNotification.defaults |= Notification.DEFAULT_SOUND;
            myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
            myNotification.setLatestEventInfo(context,
                    (CharSequence)(object)Title,
                    (CharSequence)(object)Content,
               pendingIntent);

            notificationManager.notify(id, myNotification);
        }
        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 Title = "Notification!";

            var TargetUri = "http://www.jsc-solutions.net";

            if (value0.hasExtra("data0"))
                Title = value0.getStringExtra("data0");

            if (value0.hasExtra("data1"))
                TargetUri = value0.getStringExtra("data1");


            var myNotification = new Notification(
                // http://docs.since2006.com/android/2.1-drawables.php
                android.R.drawable.ic_menu_view,
                Title,
                //java.lang.JavaSystem.currentTimeMillis()
                java.lang.System.currentTimeMillis()
            );

            var context = getApplicationContext();

            var myIntent = new Intent(Intent.ACTION_VIEW,
                android.net.Uri.parse(TargetUri));

            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,
                    Title,
                    TargetUri,
               pendingIntent);
            notificationManager.notify(1, myNotification);


            this.stopSelf();

            return 0;
        }
Пример #15
0
 protected virtual void onNewIntent(android.content.Intent value)
 {
 }
        protected override void onCreate(Bundle savedInstanceState)
        {
            var activity = this;
            // http://stackoverflow.com/questions/11425020/actionbar-in-a-dialogfragment
            //To show activity as dialog and dim the background, you need to declare android:theme="@style/PopupTheme" on for the chosen activity on the manifest
            //activity.requestWindowFeature(Window.FEATURE_ACTION_BAR);
            //activity.getWindow().setFlags(WindowManager_LayoutParams.FLAG_DIM_BEHIND, WindowManager_LayoutParams.FLAG_DIM_BEHIND);
            //activity.getWindow().setFlags(WindowManager_LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager_LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //var @params = activity.getWindow().getAttributes();
            ////@params.height = WindowManager_LayoutParams.FILL_PARENT;
            ////@params.width = 850; //fixed width
            ////@params.height = 450; //fixed width
            //@params.alpha = 1.0f;
            //@params.dimAmount = 0.5f;
            //activity.getWindow().setAttributes(@params);
            //activity.getWindow().setLayout(850, 850);
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            var b = new Button(this).AttachTo(ll);


            // https://stackoverflow.com/questions/1898886/removing-an-activity-from-the-history-stack

            b.WithText("start secondary");
            b.AtClick(
                v =>
                {
                    foo = "hi";

                    Intent intent = new Intent(this, typeof(SecondaryActivity).ToClass());
                    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                    //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    startActivity(intent);
                }
            );

            this.AtPause += delegate { b.setText("AtPause"); };
            this.AtResume += delegate { b.setText("AtResume"); };


            AtPrepareOptions +=
                value =>
                {
                    value.clear();

                    var item1 = value.add(
                         (java.lang.CharSequence)(object)"http://abstractatech.com"
                    );



                    item1.setIcon(android.R.drawable.ic_menu_view);

                    var item2 = value.add(
                        (java.lang.CharSequence)(object)"http://jsc-solutions.net"
                    );

                    //item2.setIcon(android.R.drawable.ic_menu_edit);
                    item2.setIcon(android.R.drawable.ic_menu_view);

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

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


                    item2.setIntent(
                        ic
                    );
                };

            AtOption +=
                item =>
                {

                    //b.WithText("menu was clicked!" + (string)(object)item.getTitle());
                    b.WithText("menu was clicked!" + new { item });
                };

            var b2 = new Button(this);
            b2.setText("The other button!");
            ll.addView(b2);

            this.setContentView(sv);



            vConfigurationChanged = e =>
            {
                var orientation = getScreenOrientation();

                var SystemUiVisibility = getWindow().getDecorView().getSystemUiVisibility();

                b2.setText(
                    new
                    {
                        orientation,
                        SystemUiVisibility
                    }.ToString()
                );


                if (orientation == Configuration.ORIENTATION_LANDSCAPE)
                {
                    hideSystemUI();
                }
                else
                {
                    showSystemUI();
                }
            };

            vConfigurationChanged(null);
        }
        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20151212/androidudpclipboard
        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20160101/ovrwindwheelndk

        //        connect s6 via usb .
        // turn on wifi!
        // kill adb

        //"x:\util\android-sdk-windows\platform-tools\adb.exe"  tcpip 5555
        // restarting in TCP mode port: 5555

        //13: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
        //    inet 192.168.1.126/24 brd 192.168.1.255 scope global wlan0
        //       valid_lft forever preferred_lft forever

        // on red
        // "x:\util\android-sdk-windows\platform-tools\adb.exe" connect  192.168.1.126:5555
        // connected to 192.168.1.126:5555



        // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201511/20151121
        // http://stackoverflow.com/questions/17513502/support-for-multi-window-app-development

        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            // http://www.dreamincode.net/forums/topic/130521-android-part-iii-dynamic-layouts/

            base.onCreate(savedInstanceState);

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

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

            var b = new Button(this);

            b.setText("Vibrate!");

            var sw = Stopwatch.StartNew();



            Action cleanup = delegate { };

            Notification reuse = null;
            var notificationIntent = new Intent(this, typeof(ApplicationActivity).ToClass());
            var contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

            Action<string> SetClipboard = value =>
            {
                Console.WriteLine("SetClipboard " + new { value });

                this.runOnUiThread(
                    delegate
                    {
                        cleanup();

                        b.setText(value);




                        if (reuse != null)
                        {
                            reuse.setLatestEventInfo(
                                 this,
                                 contentTitle: value,
                                 contentText: "",
                                 contentIntent: contentIntent);

                            return;
                        }

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

                        // see http://developer.android.com/reference/android/app/Notification.html
                        var xNotification = new Notification(
                            //android.R.drawable.ic_dialog_alert,
                            android.R.drawable.ic_menu_view,
                            //tickerText: "not used?",
                            tickerText: value,


                            when: 0
                            //java.lang.System.currentTimeMillis()
                        );

                        //notification.defaults |= Notification.DEFAULT_SOUND;



                        // flags = Notification.FLAG_ONGOING_EVENT 

                        var FLAG_ONGOING_EVENT = 0x00000002;
                        //notification.flags |= Notification.FLAG_ONGOING_EVENT;
                        //xNotification.flags |= FLAG_ONGOING_EVENT;

                        xNotification.setLatestEventInfo(
                            this,
                            contentTitle: value,
                            contentText: "",
                            contentIntent: contentIntent);

                        //notification.defaults |= Notification.DEFAULT_VIBRATE;
                        //notification.defaults |= Notification.DEFAULT_LIGHTS;
                        // http://androiddrawableexplorer.appspot.com/

                        var id = (int)sw.ElapsedMilliseconds;

                        xNotificationManager.notify(id, xNotification);

                        var xVibrator = (Vibrator)this.getSystemService(Context.VIBRATOR_SERVICE);
                        xVibrator.vibrate(600);



                        #region setPrimaryClip
                        android.content.ClipboardManager clipboard = (android.content.ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
                        ClipData clip = ClipData.newPlainText("label", value);
                        clipboard.setPrimaryClip(clip);
                        #endregion

                        reuse = xNotification;


                        cleanup += delegate
                        {
                            // https://developer.android.com/reference/android/app/Notification.html

                            if (xNotification == null)
                                return;

                            xNotificationManager.cancel(id);
                        };
                    }
                );
            };


            b.AtClick(
                delegate
                {
                    SetClipboard("hello");
                }
            );



            // Z:\jsc.svn\examples\c\android\Test\TestNDKUDP\TestNDKUDP\xNativeActivity.cs

            #region lets listen to incoming udp
            // could we define our chrome app inline in here?
            // or in a chrome app. could we define the android app inline?
            #region ReceiveAsync
            Action<IPAddress> f = async nic =>
            {
                b.setText("awaiting at " + nic);


                WifiManager wifi = (WifiManager)this.getSystemService(Context.WIFI_SERVICE);
                var lo = wifi.createMulticastLock("udp:49814");
                lo.acquire();

                // Z:\jsc.svn\examples\java\android\AndroidUDPClipboard\ApplicationActivity.cs
                // X:\jsc.svn\examples\java\android\forms\FormsUDPJoinGroup\FormsUDPJoinGroup\ApplicationControl.cs
                // X:\jsc.svn\examples\java\android\LANBroadcastListener\LANBroadcastListener\ApplicationActivity.cs
                var uu = new UdpClient(49814);
                uu.JoinMulticastGroup(IPAddress.Parse("239.1.2.3"), nic);
                while (true)
                {
                    // cannot get data from RED?
                    var x = await uu.ReceiveAsync(); // did we jump to ui thread?
                    //Console.WriteLine("ReceiveAsync done " + Encoding.UTF8.GetString(x.Buffer));
                    var data = Encoding.UTF8.GetString(x.Buffer);



                    // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150704
                    // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150704/mousedown
                    SetClipboard(data);
                }
            };

            // WithEach defined at?
            NetworkInterface.GetAllNetworkInterfaces().WithEach(
                n =>
                {
                    // X:\jsc.svn\examples\java\android\forms\FormsUDPJoinGroup\FormsUDPJoinGroup\ApplicationControl.cs
                    // X:\jsc.svn\core\ScriptCoreLibJava\BCLImplementation\System\Net\NetworkInformation\NetworkInterface.cs

                    var IPProperties = n.GetIPProperties();
                    var PhysicalAddress = n.GetPhysicalAddress();



                    foreach (var ip in IPProperties.UnicastAddresses)
                    {
                        // ipv4
                        if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                        {
                            if (!IPAddress.IsLoopback(ip.Address))
                                if (n.SupportsMulticast)
                                    f(ip.Address);
                        }
                    }




                }
            );
            #endregion


            #endregion

            // jsc could pass this ptr to ctor for context..
            var t = new EditText(this) { };

            t.AttachTo(ll);

            ll.addView(b);



            this.setContentView(sv);


            //this.ShowLongToast("http://my.jsc-solutions.net x");
        }
Пример #18
0
		internal static void FinishActivity (Activity activity, int resultCode, Intent resultData)
		{
			ThreadPool.QueueUserWorkItem ((state) => FinishActivity ());
		}
Пример #19
0
		public override Drawable getActivityLogo (Intent intent)
		{
			throw new NotImplementedException ();
		}
Пример #20
0
		public override List<ResolveInfo> queryIntentServices (Intent intent, int flags)
		{
			throw new NotImplementedException ();
		}
Пример #21
0
		public override ResolveInfo resolveService (Intent intent, int flags)
		{
			throw new NotImplementedException ();
		}
Пример #22
0
		public override List<ResolveInfo> queryBroadcastReceivers (Intent intent, int flags)
		{
			throw new NotImplementedException ();
		}
Пример #23
0
		public override List<ResolveInfo> queryIntentActivityOptions (ComponentName caller, Intent[] specifics, Intent intent, int flags)
		{
			throw new NotImplementedException ();
		}
        // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201402/20140223-nfc
        // http://blog.atlasrfidstore.com/rfid-vs-nfc

        static ApplicationWebService()
        {
            // http://lifehacker.com/run-an-action-when-you-remove-your-phone-from-an-nfc-ta-1208446359
            // https://groups.google.com/forum/#!topic/android-developers/8-17f6ZLYJY

            //  android:launchMode="singleTop"
            // http://www.intridea.com/blog/2011/6/16/android-understanding-activity-launchmode
            Console.WriteLine("enter ApplicationWebService " + new { Thread.CurrentThread.ManagedThreadId });

            // http://mobile.tutsplus.com/tutorials/android/reading-nfc-tags-with-android/
            // http://stackoverflow.com/questions/10848134/android-on-nfc-read-close-activity-not-the-main-activity
            // http://stackoverflow.com/questions/17989055/nfc-not-able-to-detect-a-tag
            // http://stackoverflow.com/questions/5685946/nfc-broadcastreceiver-problem

            var activity = ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext as ScriptCoreLib.Android.CoreAndroidWebServiceActivity;
            var adapter = android.nfc.NfcAdapter.getDefaultAdapter(activity);
            var isEnabled = adapter.isEnabled();

            Console.WriteLine(new { isEnabled });

            var intent = new Intent(
                activity,
                activity.GetType().ToClass()
                );

            // /ActivityManager(  510): startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { act=android.nfc.action.TECH_DISCOVERED cmp=AndroidNFCIsoDepTest.Activities/.ApplicationWebServiceActivity (has extras) }
            intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            //intent.addFlags(Intent.flag);
            //intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);

            // http://comments.gmane.org/gmane.comp.handhelds.android.devel/165860

            // https://code.google.com/p/android/issues/detail?id=4155
            //            Well onNewIntent will only be called when the activity has "singleTop" property and
            //exists in the activity stack(not destroyed)
            //intent.addFlags(Intent.fl);
            //com.p2.A2 is an Activity with launchMode="singleTop".


            //But without Intent.FLAG_ACTIVITY_SINGLE_TOP being set,
            //A2.onNewIntent() will not be invoked.
            // http://comments.gmane.org/gmane.comp.handhelds.android.devel/165860
            var pendingIntent = PendingIntent.getActivity(
                activity,
                0,
                intent,
                0
            );

            //var techList = new[]
            //{ 
            //    //  [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.Ndef]
            //    //  dispatch tag: TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.NdefFormatable] message: null
            //    new [] { typeof(android.nfc.tech.MifareClassic).FullName },
            //    new [] {     typeof(android.nfc.tech.NfcA).FullName},
            //    new [] {     typeof(android.nfc.tech.Ndef).FullName},
            //    new [] {     typeof(android.nfc.tech.NdefFormatable).FullName },

            //    // current javacards? (ISO 14443-4)
            //    new [] {     typeof(android.nfc.tech.IsoDep).FullName },


            //};

            // http://124.16.139.131:24080/lxr/source/packages/apps/Nfc/src/com/android/nfc/NfcDispatcher.java?v=android-4.0.4


            //String[][] techList = new String[][] { new String[] { NfcA.class.getName(),
            //NfcB.class.getName(), NfcF.class.getName(),
            //NfcV.class.getName(), IsoDep.class.getName(),
            //MifareClassic.class.getName(),
            //MifareUltralight.class.getName(), Ndef.class.getName() } };



            // Notice that this is the same filter as in our manifest.
            var filters = new IntentFilter[1];

            filters[0] = new IntentFilter();

            // https://code.google.com/p/android/issues/detail?id=37673
            // http://www.xda-developers.com/android/activate-actions-upon-removal-of-nfc-tags/
            //filters[0].addAction(NfcAdapter.ACTION_TAG_LOST);

            // https://android.googlesource.com/platform/frameworks/base.git/+/android-4.2.2_r1/core/java/android/nfc/NfcAdapter.java
            filters[0].addAction("android.nfc.action.TAG_LOST");

            filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
            filters[0].addAction(NfcAdapter.ACTION_TAG_DISCOVERED);
            filters[0].addAction(NfcAdapter.ACTION_TECH_DISCOVERED);


            filters[0].addCategory(Intent.CATEGORY_DEFAULT);

            //V:\src\AndroidNFCIsoDepTest\ApplicationWebService.java:57: unreported exception android.content.IntentFilter.MalformedMimeTypeException; must be caught or declared to be thrown
            try
            {
                filters[0].addDataType("*/*");
            }
            catch
            {
                throw;
            }

            //            D/NfcDispatcher(  747): Set Foreground Dispatch
            //D/dalvikvm(20170): GC_CONCURRENT freed 488K, 8% free 7978K/8584K, paused 4ms+2ms, total 27ms
            //D/dalvikvm(  581): GC_CONCURRENT freed 4091K, 44% free 12001K/21124K, paused 3ms+5ms, total 32ms
            //D/NfcDispatcher(  747): dispatch tag: TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.Ndef] message: NdefMessage [NdefRecord tnf=4 type=70696C65742E65653A656B616172743A32 payload=66195F26063133303130385904202020205F28033233335F2701316E1B5A13333038363439303039303030333032313336315304FDCCD727, NdefRecord tnf=1 type=536967 payload=01020080B489DEDA8C2271386B7962250063A7C7C8612C3D58C8CD44D674F9D1615E80C72D961F8AC822C3188D48EFC7DA9DA3FF5C306E1EF54E0610F66D1C891CC59428A27CAA4211D4040527CF9BCD16F20E0B3116966AFC2390B7EF30CCC877B8532281CA3CBE286D295AECEA4447FD62874872A46099D6CEED99ED6766B829FD3FDF800025687474703A2F2F70696C65742E65652F6372742F33303836343930302D303030312E637274]
            //D/dalvikvm(  747): GC_CONCURRENT freed 491K, 10% free 8255K/9160K, paused 3ms+1ms, total 33ms
            //D/dalvikvm(  747): WAIT_FOR_CONCURRENT_GC blocked 8ms
            //D/NfcHandover(  747): tryHandover(): NdefMessage [NdefRecord tnf=4 type=70696C65742E65653A656B616172743A32 payload=66195F26063133303130385904202020205F28033233335F2701316E1B5A13333038363439303039303030333032313336315304FDCCD727, NdefRecord tnf=1 type=536967 payload=01020080B489DEDA8C2271386B7962250063A7C7C8612C3D58C8CD44D674F9D1615E80C72D961F8AC822C3188D48EFC7DA9DA3FF5C306E1EF54E0610F66D1C891CC59428A27CAA4211D4040527CF9BCD16F20E0B3116966AFC2390B7EF30CCC877B8532281CA3CBE286D295AECEA4447FD62874872A46099D6CEED99ED6766B829FD3FDF800025687474703A2F2F70696C65742E65652F6372742F33303836343930302D303030312E637274]
            //I/ActivityManager(  440): START u0 {flg=0x10008000 cmp=com.android.nfc/.NfcRootActivity (has extras)} from pid 747
            //D/NfcDispatcher(  747): Set Foreground Dispatch
            //I/NfcDispatcher(  747): matched single TECH
            //I/ActivityManager(  440): START u0 {act=android.nfc.action.TECH_DISCOVERED cmp=com.google.android.tag/com.android.apps.tag.TagViewer (has extras)} from pid 747
            //I/ActivityManager(  440): Displayed com.google.android.tag/com.android.apps.tag.TagViewer: +100ms (total +114ms)
            //W/IInputConnectionWrapper(20170): showStatusIcon on inactive InputConnection
            //I/CalendarProvider2(17732): Sending notification intent: Intent { act=android.intent.action.PROVIDER_CHANGED dat=content://com.android.calendar }
            //W/ContentResolver(17732): Failed to get type for: content://com.android.calendar (Unknown URL content://com.android.calendar)


            activity.AtNewIntent +=
                i =>
                {
                    var action = i.getAction();





                    Console.WriteLine("AndroidNFCIsoDepTest AtNewIntent " + new { action });

                    //I/System.Console(25300): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED }

                    #region android.nfc.action.TECH_DISCOVERED
                    if (action == "android.nfc.action.TECH_DISCOVERED")
                    {
                        //                    U:\src\AndroidNFCIsoDepTest\ApplicationWebService___c__DisplayClass4.java:93: <identifier> expected
                        //private static Tag _<.cctor>b__0_Isinst_0064(Object _0064)
                        //                     ^

                        //                        I/System.Console(26970): AtPause
                        //D/NfcDispatcher(  747): Set Foreground Dispatch
                        //I/System.Console(26970): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED }
                        //I/System.Console(26970): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, tag =  }
                        //D/AndroidRuntime(26970): Shutting down VM
                        //W/dalvikvm(26970): threadid=1: thread exiting with uncaught exception (group=0x419dc700)
                        //I/ActivityManager(  440): START u0 {act=android.nfc.action.TECH_DISCOVERED flg=0x20000000 cmp=AndroidNFCIsoDepTest.Activities/.ApplicationWebServiceActivity (has extras)} from pid -1
                        //W/ActivityManager(  440): startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { act=android.nfc.action.TECH_DISCOVERED flg=0x20000000 cmp=AndroidNFCIsoDepTest.Activities/.ApplicationWebServiceActivity (has extras) }

                        //var tag = (Tag)intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

                        //Console.WriteLine("AtNewIntent " + new { action, tag });

                        // D/NfcDispatcher(  747): dispatch tag: TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.Ndef] 
                        // message: NdefMessage 
                        // [NdefRecord tnf=4 type=70696C65742E65653A656B616172743A32 payload=66195F26063133303130385904202020205F28033233335F2701316E1B5A13333038363439303039303030333032313336315304FDCCD727, 
                        //  NdefRecord tnf=1 type=536967 payload=01020080B489DEDA8C2271386B7962250063A7C7C8612C3D58C8CD44D674F9D1615E80C72D961F8AC822C3188D48EFC7DA9DA3FF5C306E1EF54E0610F66D1C891CC59428A27CAA4211D4040527CF9BCD16F20E0B3116966AFC2390B7EF30CCC877B8532281CA3CBE286D295AECEA4447FD62874872A46099D6CEED99ED6766B829FD3FDF800025687474703A2F2F70696C65742E65652F6372742F33303836343930302D303030312E637274
                        // ]



                        //                        I/ActivityManager(  440): START u0 {act=android.nfc.action.TECH_DISCOVERED flg=0x20000000 cmp=AndroidNFCIsoDepTest.Activities/.ApplicationWebServiceActivity (has extras)} from pid -1
                        //W/ActivityManager(  440): startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { act=android.nfc.action.TECH_DISCOVERED flg=0x20000000 cmp=AndroidNFCIsoDepTest.Activities/.ApplicationWebServiceActivity (has extras) }
                        //I/System.Console(30978): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED }
                        //I/NfcDispatcher(  747): matched TECH override
                        //I/System.Console(30978): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG }
                        //I/System.Console(30978): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG, p = TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.NdefFormatable], FullName = android.nfc.Tag }
                        //I/System.Console(30978): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.ID }
                        //I/System.Console(30978): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.ID, p = [B@4212cfc8, FullName = [B }
                        //I/System.Console(30978): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.ID, p = [B@4212cfc8, FullName = [B, HexString = fc4969f9 }
                        //I/System.Console(30978): AtResume

                        // https://groups.google.com/forum/#!topic/android-developers/8-17f6ZLYJY
                        //http://stackoverflow.com/questions/9009043/android-nfc-intercept-all-tags
                        var extras = i.getExtras();
                        var ks = extras.keySet();
                        var iterator = ks.iterator();
                        while (iterator.hasNext())
                        {
                            var current = (string)iterator.next();

                            Console.WriteLine("AtNewIntent " + new { action, current });



                            // I/System.Console(29237): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG, p = TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.Ndef], FullName = android.nfc.Tag }
                            // http://stackoverflow.com/questions/5968896/listing-all-extras-of-an-intent
                            extras.get(current).With(
                                p =>
                                {
                                    Console.WriteLine("AtNewIntent " + new { action, current, p, p.GetType().FullName });

                                    (p as Tag).With(
                                       tag =>
                                       {
                                           var id = (byte[])(object)tag.getId();

                                           Console.WriteLine("AtNewIntent " + new { action, current, id = id.ToHexString(), Thread.CurrentThread.ManagedThreadId });

                                           //I/System.Console(32331): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG, p = TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.Ndef], id = fdccd727, tech = android.nfc.tech.MifareClassic }
                                           //I/System.Console(32331): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG, p = TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.Ndef], id = fdccd727, tech = android.nfc.tech.NfcA }
                                           //I/System.Console(32331): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG, p = TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.Ndef], id = fdccd727, tech = android.nfc.tech.Ndef }

                                           //I/System.Console(32331): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG, p = TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.NdefFormatable], id = fc4969f9, tech = android.nfc.tech.MifareClassic }
                                           //I/System.Console(32331): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG, p = TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.NdefFormatable], id = fc4969f9, tech = android.nfc.tech.NfcA }
                                           //I/System.Console(32331): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG, p = TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.NdefFormatable], id = fc4969f9, tech = android.nfc.tech.NdefFormatable }

                                           tag.getTechList().WithEach(
                                               tech =>
                                               {
                                                   Console.WriteLine("AtNewIntent " + new { action, current, id = id.ToHexString(), tech });

                                                   if (tech == typeof(android.nfc.tech.MifareClassic).FullName)
                                                   {
                                                       android.nfc.tech.MifareClassic.get(tag).With(
                                                           m =>
                                                           {


                                                           }
                                                       );
                                                   }


                                                   if (tech == typeof(android.nfc.tech.NfcA).FullName)
                                                   {
                                                       android.nfc.tech.NfcA.get(tag).With(
                                                           m =>
                                                           {

                                                           }
                                                       );
                                                   }

                                                   if (tech == typeof(android.nfc.tech.IsoDep).FullName)
                                                   {
                                                       android.nfc.tech.IsoDep.get(tag).With(
                                                           m =>
                                                           {
                                                               try
                                                               {
                                                                   Console.WriteLine("Isodep exists");

                                                                   //AID A0 A1 A2 A3 A4 00 03 01
                                                                   byte[] AID = {0x00, 0xA4, 0x04, 0x00, 0x08, //Applet selection APDU
                                                                                    0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0x00, 0x03, 0x01 }; //Applet AID
                                                                   var sByteArr = (sbyte[])(object)AID;
                                                                   m.connect();
                                                                   var res = m.transceive(sByteArr);
                                                                   //Console.WriteLine("Result " + Convert.ToBase64String((byte[])(object)res));

                                                                   var resString = ((byte[])(object)res).ToHexString();

                                                                   Console.WriteLine("Result = " + resString);

                                                                   //Console.WriteLine("Result[0] = " + res[0].ToString());
                                                                   //Console.WriteLine("Result[1] = " + res[1].ToString());
                                                                   Console.WriteLine("Result lenght = " + res.Length);

                                                                    //I/System.Console( 9340): Isodep exists
                                                                    //I/System.Console( 9340): Result [B@427ebd50
                                                                    //I/System.Console( 9340): Result = 9000
                                                                    //I/System.Console( 9340): Result lenght = 2
                                                                    //I/System.Console( 9340): Applet select failed

                                                                   if (resString == "9000")
                                                                   {
                                                                        //I/System.Console(10829): Isodep exists
                                                                        //I/System.Console(10829): Result = 9000
                                                                        //I/System.Console(10829): Result lenght = 2
                                                                        //I/System.Console(10829): Succsessful applet selection
                                                                        //I/System.Console(10829): Last name =6f00
                                                                        //I/System.Console(10829): Last name len =2
                                                                        //I/System.Console(10829): First name =6f00
                                                                        //I/System.Console(10829): First name len =2


                                                                       Console.WriteLine("Succsessful applet selection");

                                                                       byte[] lastName = { 0x00, 0xB2, 0x01, 0x04, 0x00 };
                                                                       byte[] firstName = { 0x00, 0xB2, 0x02, 0x04, 0x00 };

                                                                       var t1 = (sbyte[])(object)lastName;
                                                                       var t2 = (sbyte[])(object)firstName;
                                                                       var lastN = m.transceive(t1);
                                                                       Console.WriteLine("Last name =" + ((byte[])(object)lastN).ToHexString());
                                                                       Console.WriteLine("Last name len =" + lastN.Length);
                                                                       

                                                                       var firstN = m.transceive(t2);
                                                                       Console.WriteLine("First name =" + ((byte[])(object)firstN).ToHexString());
                                                                       Console.WriteLine("First name len =" + firstN.Length);

                                                                        //I/System.Console(11937): Isodep exists
                                                                        //I/System.Console(11937): Result = 9000
                                                                        //I/System.Console(11937): Result lenght = 2
                                                                        //I/System.Console(11937): Succsessful applet s
                                                                        //I/System.Console(11937): Last name =6b6969766
                                                                        //I/System.Console(11937): Last name len =8
                                                                        //I/System.Console(11937): First name =6a6f6e61
                                                                        //I/System.Console(11937): First name len =7
                                                                   }
                                                                   else
                                                                   {
                                                                       Console.WriteLine("Applet select failed");
                                                                   }
                                                               }
                                                               catch (Exception e)
                                                               {
                                                                   Console.WriteLine("Exception ="+e.Message);

                                                               }
                                                               
                                                           }
                                                       );
                                                   }

                                               }
                                           );

                                           //tag.
                                       }
                                    );

                                    (p as byte[]).With(
                                        bytes =>
                                        {
                                            var HexString = bytes.ToHexString();

                                            Console.WriteLine("AtNewIntent " + new { action, current, p, p.GetType().FullName, HexString });
                                        }
                                    );

                                    // https://android.googlesource.com/platform/packages/apps/Nfc/+/android-4.2.1_r1.2/nci/src/com/android/nfc/dhimpl/NativeNfcTag.java

                                    //(p as android.os.Parcelable[]).With(
                                    //     m =>
                                    //     {

                                    //         Console.WriteLine("AtNewIntent " + new { action, current, records = m.getRecords().Length });

                                    //         m.getRecords().WithEach(
                                    //             r =>
                                    //             {
                                    //                 Console.WriteLine("AtNewIntent " + new { action, current, id = ((byte[])(object)r.getId()).ToHexString() });

                                    //             }
                                    //         );
                                    //     }
                                    // );
                                }
                            );

                        }

                        //                        I/System.Console(29527): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED }
                        //I/System.Console(29527): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG }
                        //I/System.Console(29527): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG, p = TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.Ndef], FullName = android.nfc.Tag }
                        //I/System.Console(29527): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.ID }
                        //I/System.Console(29527): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.ID, p = [B@42156c88, FullName = [B }
                        //I/System.Console(29527): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.NDEF_MESSAGES }
                        //I/System.Console(29527): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.NDEF_MESSAGES, p = [Landroid.os.Parcelable;@42156e98, FullName = [Landroid.os.Parcelable; }
                        //I/System.Console(29527): AtResume





                        //                        I/System.Console(28867): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED }
                        //I/System.Console(28867): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG }
                        //I/System.Console(28867): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.ID }
                        //I/System.Console(28867): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.NDEF_MESSAGES }




                        //var id = tag.getId();

                        //Console.WriteLine("AtNewIntent " + new { action, tag, id.Length, id = ((byte[])(object)id).ToHexString() });

                        //tag.getTechList().WithEach(
                        //    tech =>
                        //    {
                        //        Console.WriteLine("AtNewIntent " + new { action, tech });
                        //    }
                        //);
                        //tag.get
                    }
                    #endregion
                };

            // who is using it?
            activity.AtResume +=
                delegate
                {

                    Console.WriteLine("AndroidNFCIsoDepTest AtResume");
                    adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
                };

            //     Caused by: java.lang.IllegalStateException: Foreground dispatch can only be enabled when your activity is resumed
            //at android.nfc.NfcAdapter.enableForegroundDispatch(NfcAdapter.java:1135)

            Console.WriteLine("before AndroidNFCIsoDepTest enableForegroundDispatch ?");
            //adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);


            activity.AtPause +=
               delegate
               {
                   Console.WriteLine("AndroidNFCIsoDepTest AtPause");
                   adapter.disableForegroundDispatch(activity);
               };
        }
        // "x:\util\android-sdk-windows\platform-tools\adb.exe"  tcpip 5555
        // restarting in TCP mode port: 5555

        // "x:\util\android-sdk-windows\platform-tools\adb.exe" connect 192.168.1.126:5555
        // connected to 192.168.1.126:5555

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

        // lets verify this thing . deploy over wifi.

        //C:\Windows\system32> "x:\util\android-sdk-windows\platform-tools\adb.exe" shell netcfg
        //wlan0    UP                               192.168.1.126/24  0x00001043 e8:50:8b:7d:27:7c

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

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            //ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            var b = new Button(this).AttachTo(ll);

            b.WithText("before AtClick");
            b.AtClick(
                v =>
                {
                    b.setText("AtClick");
                }
            );


            this.setContentView(sv);



            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


                    Console.WriteLine("enter async " + new { Thread.CurrentThread.ManagedThreadId });

                    // X:\jsc.svn\examples\javascript\chrome\apps\ChromeTCPServerAsync\ChromeTCPServerAsync\Application.cs
                    await Task.Delay(100);

                    Console.WriteLine("after delay" + new { Thread.CurrentThread.ManagedThreadId });

                    // Additional information: Only one usage of each socket address (protocol/network address/port) is normally permitted
                    // close the other server!
                    var l = new TcpListener(IPAddress.Any, 8080);

                    l.Start();


                    var href =
                        "http://127.0.0.1:8080";

                    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);
                        }
                    );



                    new { }.With(
                        async delegate
                        {
                            while (true)
                            {
                                var c = await l.AcceptTcpClientAsync();

                                Console.WriteLine("accept " + new { c, Thread.CurrentThread.ManagedThreadId });

                                yield(c);
                            }
                        }
                    );

                    // jump back to main thread..
                    s.Release();
                }
            );
        }
        protected override void onCreate(Bundle savedInstanceState)
        {
            var activity = this;
            // http://stackoverflow.com/questions/11425020/actionbar-in-a-dialogfragment
            //To show activity as dialog and dim the background, you need to declare android:theme="@style/PopupTheme" on for the chosen activity on the manifest
            //activity.requestWindowFeature(Window.FEATURE_ACTION_BAR);
            //activity.getWindow().setFlags(WindowManager_LayoutParams.FLAG_DIM_BEHIND, WindowManager_LayoutParams.FLAG_DIM_BEHIND);
            //activity.getWindow().setFlags(WindowManager_LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager_LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //var @params = activity.getWindow().getAttributes();
            ////@params.height = WindowManager_LayoutParams.FILL_PARENT;
            ////@params.width = 850; //fixed width
            ////@params.height = 450; //fixed width
            //@params.alpha = 1.0f;
            //@params.dimAmount = 0.5f;
            //activity.getWindow().setAttributes(@params);
            //activity.getWindow().setLayout(850, 850);
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            //ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            var b = new Button(this).AttachTo(ll);



            b.WithText("before AtClick");
            b.AtClick(
                v =>
                {
                    b.setText("AtClick");
                }
            );


            AtPrepareOptions +=
                value =>
                {
                    value.clear();

                    var item1 = value.add(
                         (java.lang.CharSequence)(object)"http://abstractatech.com"
                    );



                    item1.setIcon(android.R.drawable.ic_menu_view);

                    var item2 = value.add(
                        (java.lang.CharSequence)(object)"http://jsc-solutions.net"
                    );

                    //item2.setIcon(android.R.drawable.ic_menu_edit);
                    item2.setIcon(android.R.drawable.ic_menu_view);

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

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


                    item2.setIntent(
                        ic
                    );
                };

            AtOption +=
                item =>
                {

                    //b.WithText("menu was clicked!" + (string)(object)item.getTitle());
                    b.WithText("menu was clicked!" + new { item });
                };

            var b2 = new Button(this);
            b2.setText("The other button!");
            ll.addView(b2);

            this.setContentView(sv);
        }
        public override void onCreate()
        {
            base.onCreate();

            Console.WriteLine("enter LocalApplication onCreate, first time?");

            // https://stackoverflow.com/questions/7686482/when-does-applications-oncreate-method-is-called-on-android
            Toast.makeText(this, "LocalApplication", Toast.LENGTH_LONG).show();

            // . To open these resources with a raw InputStream, call Resources.openRawResource() with the resource ID, which is R.raw.filename.
            // However, if you need access to original file names and file hierarchy, you might consider saving some resources in the assets/ directory (instead of res/raw/). Files in assets/ are not given a resource ID, so you can read them only using AssetManager.

            var listByRoot = default(Action<Activity, LinearLayout, string>);

            listByRoot =
                (activity, ll, root) =>
                {
                    try
                    {
                        // http://developer.android.com/reference/android/content/res/AssetManager.html
                        var assets = activity.getResources().getAssets();

                        var list = assets.list(root);


                        new Button(activity).WithText("assets: " + new { list.Length, root }).AttachTo(ll);

                        foreach (var item in list)
                        {
                            //                            E/AndroidRuntime(25423): Caused by: java.io.FileNotFoundException: images
                            //E/AndroidRuntime(25423):        at android.content.res.AssetManager.openNonAssetFdNative(Native Method)

                            //var a = fd.getFileDescriptor();
                            var _item = item;

                            new Button(activity).AttachTo(ll).With(
                                i =>
                                {
                                    var fd = default(AssetFileDescriptor);

                                    try
                                    {
                                        // http://stackoverflow.com/questions/5647253/is-there-a-way-to-open-file-as-file-object-from-androids-assets-folder

                                        fd = assets.openFd(item);
                                        //fd = assets.openNonAssetFd(item);
                                        i.WithText(root + "/" + item + " " + new { Length = fd.getLength() });
                                    }
                                    catch
                                    {
                                        i.WithText("dir: " + item);

                                        i.AtClick(
                                            delegate
                                            {
                                                // hop to another activity

                                                Intent intent = new Intent(activity, typeof(SecondaryActivity).ToClass());
                                                intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

                                                // share scope
                                                intent.putExtra("_item", _item);

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

                                                //E/AndroidRuntime(10688): Caused by: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
                                                //E/AndroidRuntime(10688):        at android.app.ContextImpl.startActivity(ContextImpl.java:1611)
                                                //E/AndroidRuntime(10688):        at android.app.ContextImpl.startActivity(ContextImpl.java:1598)
                                                //E/AndroidRuntime(10688):        at android.content.ContextWrapper.startActivity(ContextWrapper.java:337)

                                                //listByRoot(_item);
                                            }
                                        );

                                    }

                                }
                            );
                        }
                    }
                    catch
                    {
                        throw;
                    }
                };

            #region ApplicationActivity
            ApplicationActivity.vCreate = (activity, savedInstanceState) =>
            {
                var myPid = android.os.Process.myPid();

                activity.setTitle("root " + new { myPid });

                var sv = new ScrollView(activity);
                var ll = new LinearLayout(activity);
                ll.setOrientation(LinearLayout.VERTICAL);
                sv.addView(ll);

                activity.setContentView(sv);

                // how many readonly assets have we added via nugets?

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


                //[javac] W:\src\TestNuGetAssetsConsumer\Activities\ApplicationActivity___c__DisplayClass1.java:32: error: unreported exception IOException; must be caught or declared to be thrown
                //[javac]         stringArray0 = assets.list("");



                listByRoot(activity, ll, "");

            };
            #endregion

            #region SecondaryActivity
            SecondaryActivity.vCreate = (activity, savedInstanceState) =>
            {
                var sv = new ScrollView(activity);
                var ll = new LinearLayout(activity);
                ll.setOrientation(LinearLayout.VERTICAL);
                sv.addView(ll);
                activity.setContentView(sv);

                // resume scope
                var _item = activity.getIntent().getExtras().getString("_item");

                // http://stackoverflow.com/questions/19631894/is-there-a-way-to-get-current-process-name-in-android
                // http://stackoverflow.com/questions/6567768/how-can-an-android-application-have-more-than-one-process
                var myPid = android.os.Process.myPid();
                //Process.GetCurrentProcess().Id;

                //activity.getPackageManager

                activity.setTitle(_item + new { myPid });


                //b.WithText("! secondary " + new { _item });
                //b.AtClick(
                //    v =>
                //    {
                //        activity.finish();
                //    }
                //);

                listByRoot(activity, ll, _item);

            };
            #endregion

        }
            public override void onReceive(Context arg0, Intent arg1)
            {
                // TODO Auto-generated method stub   

                if (AtReceive != null)
                    AtReceive();
            }
        static ApplicationWebService_poll_onnfc()
        {
            // http://lifehacker.com/run-an-action-when-you-remove-your-phone-from-an-nfc-ta-1208446359
            // https://groups.google.com/forum/#!topic/android-developers/8-17f6ZLYJY

            //  enter ApplicationWebService { ManagedThreadId = 2029 }
            Console.WriteLine("enter ApplicationWebService_poll_onnfc " + new { Thread.CurrentThread.ManagedThreadId });

            // http://mobile.tutsplus.com/tutorials/android/reading-nfc-tags-with-android/
            // http://stackoverflow.com/questions/10848134/android-on-nfc-read-close-activity-not-the-main-activity
            // http://stackoverflow.com/questions/17989055/nfc-not-able-to-detect-a-tag
            // http://stackoverflow.com/questions/5685946/nfc-broadcastreceiver-problem

            var activity = ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext as ScriptCoreLib.Android.CoreAndroidWebServiceActivity;

            var adapter = android.nfc.NfcAdapter.getDefaultAdapter(
                activity
            );

            var isEnabled = adapter.isEnabled();

            Console.WriteLine(new { isEnabled });




            var intent = new Intent(
                activity,
                activity.GetType().ToClass()
                );

            intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

            var pendingIntent = PendingIntent.getActivity(
                activity,
                0,
                intent,
                0
            );

            var filters = new IntentFilter[1];
            var techList = new[]
            { 
                //  [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.Ndef]
                //  dispatch tag: TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.NdefFormatable] message: null
                new [] { typeof(android.nfc.tech.MifareClassic).FullName },
                new [] { typeof(android.nfc.tech.NfcA).FullName},
                new [] { typeof(android.nfc.tech.Ndef).FullName},
                new [] { typeof(android.nfc.tech.NdefFormatable).FullName },

				// current javacards? (ISO 14443-4)
				new [] {     typeof(android.nfc.tech.IsoDep).FullName },
			};

            // http://124.16.139.131:24080/lxr/source/packages/apps/Nfc/src/com/android/nfc/NfcDispatcher.java?v=android-4.0.4


            //String[][] techList = new String[][] { new String[] { NfcA.class.getName(),
            //NfcB.class.getName(), NfcF.class.getName(),
            //NfcV.class.getName(), IsoDep.class.getName(),
            //MifareClassic.class.getName(),
            //MifareUltralight.class.getName(), Ndef.class.getName() } };



            // Notice that this is the same filter as in our manifest.
            filters[0] = new IntentFilter();

            // https://code.google.com/p/android/issues/detail?id=37673
            // http://www.xda-developers.com/android/activate-actions-upon-removal-of-nfc-tags/
            //filters[0].addAction(NfcAdapter.ACTION_TAG_LOST);

            // https://android.googlesource.com/platform/frameworks/base.git/+/android-4.2.2_r1/core/java/android/nfc/NfcAdapter.java
            filters[0].addAction("android.nfc.action.TAG_LOST");

            filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
            filters[0].addAction(NfcAdapter.ACTION_TAG_DISCOVERED);
            filters[0].addAction(NfcAdapter.ACTION_TECH_DISCOVERED);


            filters[0].addCategory(Intent.CATEGORY_DEFAULT);

            //V:\src\AndroidNFCExperiment\ApplicationWebService.java:57: unreported exception android.content.IntentFilter.MalformedMimeTypeException; must be caught or declared to be thrown
            try
            {
                filters[0].addDataType("*/*");
            }
            catch
            {
                throw;
            }

            activity.AtNewIntent +=
                i =>
                {
                    var action = i.getAction();

                    Console.WriteLine("AtNewIntent " + new { action });

                    //I/System.Console(25300): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED }

                    if (action == NfcAdapter.ACTION_TECH_DISCOVERED)
                    {
                        //                    U:\src\AndroidNFCExperiment\ApplicationWebService___c__DisplayClass4.java:93: <identifier> expected
                        //private static Tag _<.cctor>b__0_Isinst_0064(Object _0064)
                        //                     ^

                        //                        I/System.Console(26970): AtPause
                        //D/NfcDispatcher(  747): Set Foreground Dispatch
                        //I/System.Console(26970): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED }
                        //I/System.Console(26970): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, tag =  }
                        //D/AndroidRuntime(26970): Shutting down VM
                        //W/dalvikvm(26970): threadid=1: thread exiting with uncaught exception (group=0x419dc700)
                        //I/ActivityManager(  440): START u0 {act=android.nfc.action.TECH_DISCOVERED flg=0x20000000 cmp=AndroidNFCExperiment.Activities/.ApplicationWebServiceActivity (has extras)} from pid -1
                        //W/ActivityManager(  440): startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { act=android.nfc.action.TECH_DISCOVERED flg=0x20000000 cmp=AndroidNFCExperiment.Activities/.ApplicationWebServiceActivity (has extras) }

                        //var tag = (Tag)intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

                        //Console.WriteLine("AtNewIntent " + new { action, tag });

                        // D/NfcDispatcher(  747): dispatch tag: TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.Ndef] 
                        // message: NdefMessage 
                        // [NdefRecord tnf=4 type=70696C65742E65653A656B616172743A32 payload=66195F26063133303130385904202020205F28033233335F2701316E1B5A13333038363439303039303030333032313336315304FDCCD727, 
                        //  NdefRecord tnf=1 type=536967 payload=01020080B489DEDA8C2271386B7962250063A7C7C8612C3D58C8CD44D674F9D1615E80C72D961F8AC822C3188D48EFC7DA9DA3FF5C306E1EF54E0610F66D1C891CC59428A27CAA4211D4040527CF9BCD16F20E0B3116966AFC2390B7EF30CCC877B8532281CA3CBE286D295AECEA4447FD62874872A46099D6CEED99ED6766B829FD3FDF800025687474703A2F2F70696C65742E65652F6372742F33303836343930302D303030312E637274
                        // ]



                        //                        I/ActivityManager(  440): START u0 {act=android.nfc.action.TECH_DISCOVERED flg=0x20000000 cmp=AndroidNFCExperiment.Activities/.ApplicationWebServiceActivity (has extras)} from pid -1
                        //W/ActivityManager(  440): startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { act=android.nfc.action.TECH_DISCOVERED flg=0x20000000 cmp=AndroidNFCExperiment.Activities/.ApplicationWebServiceActivity (has extras) }
                        //I/System.Console(30978): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED }
                        //I/NfcDispatcher(  747): matched TECH override
                        //I/System.Console(30978): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG }
                        //I/System.Console(30978): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG, p = TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.NdefFormatable], FullName = android.nfc.Tag }
                        //I/System.Console(30978): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.ID }
                        //I/System.Console(30978): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.ID, p = [B@4212cfc8, FullName = [B }
                        //I/System.Console(30978): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.ID, p = [B@4212cfc8, FullName = [B, HexString = fc4969f9 }
                        //I/System.Console(30978): AtResume

                        // https://groups.google.com/forum/#!topic/android-developers/8-17f6ZLYJY
                        //http://stackoverflow.com/questions/9009043/android-nfc-intercept-all-tags
                        var extras = i.getExtras();
                        var ks = extras.keySet();
                        var iterator = ks.iterator();
                        while (iterator.hasNext())
                        {
                            var current = (string)iterator.next();

                            Console.WriteLine("AtNewIntent " + new { action, current });



                            // I/System.Console(29237): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG, p = TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.Ndef], FullName = android.nfc.Tag }
                            // http://stackoverflow.com/questions/5968896/listing-all-extras-of-an-intent
                            extras.get(current).With(
                                p =>
                                {
                                    Console.WriteLine("AtNewIntent " + new { action, current, p, p.GetType().FullName });

                                    (p as Tag).With(
                                       tag =>
                                       {
                                           var id = (byte[])(object)tag.getId();

                                           Console.WriteLine("AtNewIntent " + new { action, current, id = id.ToHexString(), Thread.CurrentThread.ManagedThreadId });

                                           History.Add(
                                                id.ToHexString()
                                            );

                                           //I/System.Console(32331): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG, p = TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.Ndef], id = fdccd727, tech = android.nfc.tech.MifareClassic }
                                           //I/System.Console(32331): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG, p = TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.Ndef], id = fdccd727, tech = android.nfc.tech.NfcA }
                                           //I/System.Console(32331): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG, p = TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.Ndef], id = fdccd727, tech = android.nfc.tech.Ndef }

                                           //I/System.Console(32331): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG, p = TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.NdefFormatable], id = fc4969f9, tech = android.nfc.tech.MifareClassic }
                                           //I/System.Console(32331): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG, p = TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.NdefFormatable], id = fc4969f9, tech = android.nfc.tech.NfcA }
                                           //I/System.Console(32331): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG, p = TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.NdefFormatable], id = fc4969f9, tech = android.nfc.tech.NdefFormatable }

                                           tag.getTechList().WithEach(
                                               tech =>
                                               {
                                                   Console.WriteLine("AtNewIntent " + new { action, current, id = id.ToHexString(), tech });

                                                   if (tech == typeof(android.nfc.tech.MifareClassic).FullName)
                                                   {
                                                       android.nfc.tech.MifareClassic.get(tag).With(
                                                           m =>
                                                           {


                                                           }
                                                       );
                                                   }


                                                   if (tech == typeof(android.nfc.tech.NfcA).FullName)
                                                   {
                                                       android.nfc.tech.NfcA.get(tag).With(
                                                           m =>
                                                           {

                                                           }
                                                       );
                                                   }
                                               }
                                           );

                                           //tag.
                                       }
                                    );

                                    (p as byte[]).With(
                                        bytes =>
                                        {
                                            var HexString = bytes.ToHexString();

                                            Console.WriteLine("AtNewIntent " + new { action, current, p, p.GetType().FullName, HexString });
                                        }
                                    );

                                    // https://android.googlesource.com/platform/packages/apps/Nfc/+/android-4.2.1_r1.2/nci/src/com/android/nfc/dhimpl/NativeNfcTag.java

                                    //(p as android.os.Parcelable[]).With(
                                    //     m =>
                                    //     {

                                    //         Console.WriteLine("AtNewIntent " + new { action, current, records = m.getRecords().Length });

                                    //         m.getRecords().WithEach(
                                    //             r =>
                                    //             {
                                    //                 Console.WriteLine("AtNewIntent " + new { action, current, id = ((byte[])(object)r.getId()).ToHexString() });

                                    //             }
                                    //         );
                                    //     }
                                    // );
                                }
                            );

                        }

                        //                        I/System.Console(29527): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED }
                        //I/System.Console(29527): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG }
                        //I/System.Console(29527): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG, p = TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.Ndef], FullName = android.nfc.Tag }
                        //I/System.Console(29527): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.ID }
                        //I/System.Console(29527): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.ID, p = [B@42156c88, FullName = [B }
                        //I/System.Console(29527): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.NDEF_MESSAGES }
                        //I/System.Console(29527): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.NDEF_MESSAGES, p = [Landroid.os.Parcelable;@42156e98, FullName = [Landroid.os.Parcelable; }
                        //I/System.Console(29527): AtResume





                        //                        I/System.Console(28867): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED }
                        //I/System.Console(28867): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.TAG }
                        //I/System.Console(28867): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.ID }
                        //I/System.Console(28867): AtNewIntent { action = android.nfc.action.TECH_DISCOVERED, current = android.nfc.extra.NDEF_MESSAGES }




                        //var id = tag.getId();

                        //Console.WriteLine("AtNewIntent " + new { action, tag, id.Length, id = ((byte[])(object)id).ToHexString() });

                        //tag.getTechList().WithEach(
                        //    tech =>
                        //    {
                        //        Console.WriteLine("AtNewIntent " + new { action, tech });
                        //    }
                        //);
                        //tag.get
                    }
                };

            // who is using it?
            activity.AtResume +=
                delegate
                {
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine("AtResume");
                    Console.WriteLine();
                    adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
                };

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("before enableForegroundDispatch");
            adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);


            activity.AtPause +=
               delegate
               {
                   Console.WriteLine();
                   Console.WriteLine();
                   Console.WriteLine("AtPause");
                   adapter.disableForegroundDispatch(activity);
               };
        }
        public /* will not be part of web service itself */ void Handler(WebServiceHandler h)
        {
            //I/System.Console(11600): #2 java.lang.NullPointerException
            //I/System.Console(11600):        at com.abstractatech.adminshell.ApplicationWebService.Handler(ApplicationWebService.java:123)
            //I/System.Console(11600):        at com.abstractatech.adminshell.Global.Serve(Global.java:93)
            //I/System.Console(11600):        at ScriptCoreLib.Ultra.WebService.InternalGlobalExtensions.InternalApplication_BeginRequest(InternalGlobalExtensions.java:347)
            //I/System.Console(11600):        at com.abstractatech.adminshell.Global.Application_BeginRequest(Global.java:36)

            // http://tools.ietf.org/html/rfc2617#section-3.2.1

            var Authorization = h.Context.Request.Headers["Authorization"];

            var AuthorizationLiteralEncoded = Authorization.SkipUntilOrEmpty("Basic ");
            var AuthorizationLiteral = Encoding.ASCII.GetString(
                Convert.FromBase64String(AuthorizationLiteralEncoded)
            );

            var AuthorizationLiteralCredentials = new
            {
                user = AuthorizationLiteral.TakeUntilOrEmpty(":"),
                password = AuthorizationLiteral.SkipUntilOrEmpty(":"),
            };

            var Host = h.Context.Request.Headers["Host"].TakeUntilIfAny(":");


            System.Console.WriteLine(
                new
                {
                    AuthorizationLiteralCredentials,
                    Host,
                    h.Context.Request.UserHostAddress,
                    h.Context.Request.HttpMethod,
                    h.Context.Request.Path,
                }.ToString());



            // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20160108
            //var a = h.Applications.FirstOrDefault(k => k.TypeName == "a");
            var a = h.Applications.FirstOrDefault(k => k.TypeName == "Applicationa");

            var Application = h.Context.Request.Headers["X-Application"];

            //if (h.Context.Request.Path == "/a")

            //if (Application == a.TypeName)

            //used 19ms, total 19ms
            //used 19ms, total 19ms
            //-byte allocation
            //sed 17ms, total 17ms
            //aused 19ms, total 19ms
            //used 15ms, total 15ms
            //used 15ms, total 15ms
            //6-byte allocation
            //sed 15ms, total 15ms
            //aused 16ms, total 16ms
            //paused 15ms, total 15ms

            if (string.Equals(Application, a.TypeName))
            {
                var OK = false;


                if (Host == h.Context.Request.UserHostAddress)
                    OK = true;

                if (!string.IsNullOrEmpty(AuthorizationLiteralCredentials.user))
                    if (!string.IsNullOrEmpty(AuthorizationLiteralCredentials.password))
                        OK = true;

                if (OK)
                {
#if Android
                    var c = ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext;

                    var intent = new Intent(c, typeof(foo.NotifyService).ToClass());

                    intent.putExtra("data0", AuthorizationLiteralCredentials.user + " is using Remote Web Shell");

                    c.startService(intent);
#endif



                    h.Context.Response.ContentType = "text/javascript";
                    h.Context.Response.AddHeader("Cache-Control", "max-age=2592000");


                    //Implementation not found for type import :
                    //type: System.Web.HttpResponse
                    //method: Void AppendCookie(System.Web.HttpCookie)
                    // not working on android?
                    h.Context.Response.SetCookie(
                        new System.Web.HttpCookie("foo", "bar")
                    );

                    //  { Length = 2211910 }
                    //h.Context.Response.Write(
                    //    "/* encrypted */".PadLeft(0x2F2F2F)
                    //);

                    // can we encrypt it? and slow it down?

                    a.DiagnosticsMakeItSlowAndAddSalt = true;

                    Console.WriteLine("lets write DiagnosticsMakeItSlowAndAddSalt");
                    h.WriteSource(a);
                    h.CompleteRequest();
                    return;
                }

                h.Context.Response.StatusCode = 401;
                h.Context.Response.AddHeader(
                    "WWW-Authenticate",
                    "Basic realm=\"Android\""
                );

                // flush?
                h.Context.Response.Write(" ");
                h.CompleteRequest();

                return;
            }
        }
        // members and types are to be extended by jsc at release build

        // tested by ?
        public abstract void onReceive(Context context, Intent intent);
 public override android.os.IBinder onBind(Intent value)
 {
     return null;
 }