Inheritance: java.lang.Object, android.os.Parcelable
        // 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");
        }
        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;
        }
Beispiel #3
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 myNotification = new Notification(
                android.R.drawable.star_on,
                (CharSequence)(object)"Notification!",
                java.lang.System.currentTimeMillis()
            );

            Context context = getApplicationContext();

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

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


            return base.onStartCommand(value0, value1, value2);
        }
        // members and types are to be extended by jsc at release build

        public void notify(int id, Notification notification)
        { }
        // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201412/20141207
        // how can we shot this from NDK?
        // what if we are in vr?
        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150607-1/surfaceview


        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            // cmd /K c:\util\android-sdk-windows\platform-tools\adb.exe logcat
            // Camera PTP

            // http://developer.android.com/guide/topics/ui/notifiers/notifications.html

            base.onCreate(savedInstanceState);

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

            ll.setOrientation(LinearLayout.VERTICAL);

            sv.addView(ll);


            int counter = 0;

            Action yield = delegate
            {
                counter++;
                var nm = (NotificationManager)this.getSystemService(Activity.NOTIFICATION_SERVICE);


                // see http://developer.android.com/reference/android/app/Notification.html
                var notification = new Notification(
                    android.R.drawable.stat_notify_sync,
                    "not used?",

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

                notification.defaults |= Notification.DEFAULT_SOUND;
                //notification.vibrate = new long[] { 100, 200, 200, 200, 200, 200, 1000, 200, 200, 200, 1000, 200 };
                notification.vibrate = new long[] { 1000 };

                //             script: error JSC1000: Java : unable to emit newarr at 'AndroidNotificationActivity.Activities.ApplicationActivity+<>c__DisplayClass2.<onCreate>b__0'#004c: System.Int64, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
                //at jsc.Languages.Java.JavaCompiler.<>c__DisplayClass1a7.<>c__DisplayClass1be.<CreateInstructionHandlers>b__162() in x:\jsc.internal.git\compiler\jsc\Languages\Java\JavaCompiler.OpCodes.cs:line 1720

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


                notification.setLatestEventInfo(
                    this,
                    "Visible in Gear VR!",
                    "yet it wont vibrate",
                    contentIntent);

                //notification.defaults |= Notification.DEFAULT_VIBRATE;
                //notification.defaults |= Notification.DEFAULT_LIGHTS;
                // http://androiddrawableexplorer.appspot.com/
                nm.notify(counter, notification);
            };


            var b = new Button(this);

            b.setText("Notify!");

            // ScriptCoreLib.Ultra ?
            b.AtClick(
                delegate
                {
                    yield();
                }
            );

            ll.addView(b);

            this.setContentView(sv);

            // X:\jsc.svn\examples\java\android\HelloOpenGLES20Activity\HelloOpenGLES20Activity\ScriptCoreLib.Android\Shader.cs

            // Error	1	'AndroidNotificationActivity.Activities.ApplicationActivity' does not contain a definition for 'ShowLongToast' and no extension method 'ShowLongToast' accepting a first argument of type 'AndroidNotificationActivity.Activities.ApplicationActivity' could be found (are you missing a using directive or an assembly reference?)	X:\jsc.svn\examples\java\android\AndroidNotificationActivity\AndroidNotificationActivity\ApplicationActivity.cs	80	18	AndroidNotificationActivity
            //this.ShowLongToast("http://jsc-solutions.net");
            this.ShowToast("http://jsc-solutions.net");

            yield();

        }
        // inspired by http://baroqueworksdev.blogspot.com/2012/09/how-to-handle-screen-onoff-and-keygurad.html



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

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


            this.setContentView(sv);


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

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

                    var mReceiver = new MyBroadcastReceiver();

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

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

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

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


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

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

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

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

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

                                // if API Level 16
                                /*
                                 * if(mKeyguard.isKeyguardLocked()){ // the keyguard is
                                 * currently locked. Log.e("","ACTION_SCREEN_ON : locked"); }
                                 */
                                if (mKeyguard.inKeyguardRestrictedInputMode())
                                {
                                    // the keyguard is currently locked.
                                    Notify("ACTION_SCREEN_ON : locked");
                                }
                                else
                                {
                                    // unlocked
                                    Notify("ACTION_SCREEN_ON : unlocked");
                                }

                            }
                            else if (action == Intent.ACTION_USER_PRESENT)
                            {
                                // The user has unlocked the screen. Enabled!
                                Notify("ACTION_USER_PRESENT");


                            }
                        };


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

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

            //this.ShowToast("http://jsc-solutions.net");
        }
        public override int onStartCommand(Intent value0, int value1, int value2)
        {
            // http://stackoverflow.com/questions/14182014/android-oncreate-or-onstartcommand-for-starting-service


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

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

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

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

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

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


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

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

                when: 0

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

            var context = getApplicationContext();

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

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



            return base.onStartCommand(value0, value1, value2);
        }
        public override int onStartCommand(Intent value0, int value1, int value2)
        {
            #region Notify
            int counter = 0;
            Action<string, string, string> Notify =
                (Title, link, search) =>
                {
                    counter++;

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


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

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

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

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

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

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

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


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

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


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

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


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

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

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

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

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

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

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

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

                    var xml = XElement.Parse(xmlstring);

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

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

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

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



            return base.onStartCommand(value0, value1, value2);
        }
Beispiel #10
0
 public void startForeground(int id, Notification notification)
 { }
        public virtual PersistentNotification getPersistentNotification(int id)
        {
            // basic notification stuff
            // http://developer.android.com/guide/topics/ui/notifiers/notifications.html
            int icon = getAppIcon();
            long when = java.lang.System.currentTimeMillis();
            Context c = getApplicationContext();
            string contentTitle = getPersistentNotificationTitle(id);
            string contentText = getPersistentNotificationMessage(id);
            string tickerText = contentTitle + ": " + contentText;

            // getPersistentNotification() is called for every new window
            // so we replace the old notification with a new one that has
            // a bigger id
            Intent notificationIntent = getPersistentNotificationIntent(id);

            PendingIntent contentIntent = null;

            if (notificationIntent != null)
            {
                contentIntent = PendingIntent.getService(this, 0,
                        notificationIntent,
                    // flag updates existing persistent notification
                        PendingIntent.FLAG_UPDATE_CURRENT);
            }

            Notification notification = new Notification(icon, tickerText, when);
            notification.setLatestEventInfo(c, contentTitle, contentText,
                    contentIntent);
            var nn = new PersistentNotification
                {
                    Notification = notification,

                    id = id,
                    contentIntent = contentIntent,
                    contentText = contentText,
                    contentTitle = contentTitle,
                    context = c
                };

            PersistentNotifications.Add(nn);

            return nn;
        }
        public virtual Notification getHiddenNotification(int id)
        {
            // same basics as getPersistentNotification()
            int icon = getHiddenIcon();
            long when = java.lang.System.currentTimeMillis();
            Context c = getApplicationContext();
            string contentTitle = getHiddenNotificationTitle(id);
            string contentText = getHiddenNotificationMessage(id);
            string tickerText = contentTitle + ": " + contentText;

            // the difference here is we are providing the same id
            Intent notificationIntent = getHiddenNotificationIntent(id);

            PendingIntent contentIntent = null;

            if (notificationIntent != null)
            {
                contentIntent = PendingIntent.getService(this, 0,
                        notificationIntent,
                    // flag updates existing persistent notification
                        PendingIntent.FLAG_UPDATE_CURRENT);
            }

            Notification notification = new Notification(icon, tickerText, when);
            notification.setLatestEventInfo(c, contentTitle, contentText,
                    contentIntent);
            return notification;
        }