public putExtra ( java arg0, string arg1 ) : android.content.Intent | ||
arg0 | java | |
arg1 | string | |
return | android.content.Intent |
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); } }
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); }
// 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); }
// 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(""); }
protected override void onCreate(Bundle savedInstanceState) { var activity = this; base.onCreate(savedInstanceState); var sv = new ScrollView(this); var ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); sv.addView(ll); var t = typeof(MemoryFile); //var m = Activator.CreateInstance(t); //E/AndroidRuntime( 4217): Caused by: java.lang.InstantiationException: class android.os.MemoryFile has no zero argument constructor //E/AndroidRuntime( 4217): at java.lang.Class.newInstance(Class.java:1641) //E/AndroidRuntime( 4217): at ScriptCoreLibJava.BCLImplementation.System.__Activator.CreateInstance(__Activator.java:27) //E/AndroidRuntime( 4217): ... 14 more //E/AndroidRuntime( 4217): Caused by: java.lang.NoSuchMethodException: <init> [] //E/AndroidRuntime( 4217): at java.lang.Class.getConstructor(Class.java:531) //E/AndroidRuntime( 4217): at java.lang.Class.getDeclaredConstructor(Class.java:510) //E/AndroidRuntime( 4217): at java.lang.Class.newInstance(Class.java:1639) //E/AndroidRuntime( 4217): ... 15 more var m_descriptor = 0; var m_fd = default(java.io.FileDescriptor); var pid = android.os.Process.myPid(); var uid = android.os.Process.myUid(); //try { m = new MemoryFile(default(string), 0); } try { m = new MemoryFile("name1", 0x07); } catch { throw; } try { m.writeBytes( new byte[] { 7, 6, 5, 4, 3, 2, 1 }, 0, 0, 0x07 ); } catch { } var buffer = new byte[0x07]; try { m.readBytes(buffer, 0, 0, 0x07); } catch { } var buffer0 = buffer[0]; //new Button(this).AttachTo(ll).WithText(new { t, m, buffer0 }.ToString()); new Button(this).AttachTo(ll).WithText(new { buffer0 }.ToString()); #region fields var fields = t.GetFields( System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance ); new Button(this).AttachTo(ll).WithText("fields: " + new { fields.Length }.ToString()); fields.WithEach( SourceField => { //E/AndroidRuntime( 9919): Caused by: java.lang.IllegalAccessException: Cannot access field: java.io.FileDescriptor android.os.MemoryFile.mFD //E/AndroidRuntime( 9919): at java.lang.reflect.Field.get(Native Method) //E/AndroidRuntime( 9919): at java.lang.reflect.Field.get(Field.java:279) //E/AndroidRuntime( 9919): at ScriptCoreLibJava.BCLImplementation.System.Reflection.__FieldInfo.GetValue(__FieldInfo.java:46) var value = SourceField.GetValue(m); var xFileDescriptor = value as java.io.FileDescriptor; if (xFileDescriptor != null) { m_fd = xFileDescriptor; var xfields = typeof(java.io.FileDescriptor).GetFields( System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance ); xfields.WithEach( xFileDescriptor_SourceField => { var xvalue = xFileDescriptor_SourceField.GetValue(value); //if (xFileDescriptor_SourceField.FieldType == typeof(int)) if (xFileDescriptor_SourceField.Name == "descriptor") { m_descriptor = (int)xvalue; } new Button(this).AttachTo(ll).WithText(xFileDescriptor_SourceField + new { xvalue }.ToString()); } ); } else { new Button(this).AttachTo(ll).WithText(new { SourceField, value }.ToString()); } } ); #endregion //var pfd = default(android.os.ParcelFileDescriptor); //try //{ // pfd = android.os.ParcelFileDescriptor.dup( // m_fd // ); //} //catch //{ //} new Button(activity).WithText("Next \n " + new { pid, uid //, //pfd = pfd.getFd(), //size = pfd.getStatSize() }).AttachTo(ll).AtClick( delegate { Intent intent = new Intent(activity, typeof(SecondaryActivity).ToClass()); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); // share scope intent.putExtra("m_descriptor", m_descriptor); intent.putExtra("pid", pid); //intent.putExtra("pfd", pfd); //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); try { Console.WriteLine("new LocalServerSocket"); var ss = new LocalServerSocket("MemoryFileDescriptor0"); // cached backgroun process? // switching to another process.. easy... activity.startActivity(intent); Console.WriteLine("before LocalServerSocket accept"); // http://alvinalexander.com/java/jwarehouse/android/core/tests/coretests/src/android/net/LocalSocketTest.java.shtml var ls = ss.accept(); Console.WriteLine("after LocalServerSocket accept"); ls.setFileDescriptorsForSend(new[] { m_fd }); ls.getOutputStream().write(42); } catch { throw; } } ); this.setContentView(sv); // https://developer.android.com/training/run-background-service/create-service.html }
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); new Button(this) .WithText("Create Event!") .AttachTo(ll) .AtClick( b => { b.setText("Done!"); // http://developer.android.com/reference/android/provider/CalendarContract.EventsColumns.html#DESCRIPTION Intent calIntent = new Intent(Intent.ACTION_INSERT); calIntent.setType("vnd.android.cursor.item/event"); calIntent.putExtra("title", "My House Party"); calIntent.putExtra("eventLocation", "My Beach House"); calIntent.putExtra("description", "A Pig Roast on the Beach"); 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()); //ttdw calIntent.putExtra("accessLevel", 0x00000002); calIntent.putExtra("availability", 0x00000000); calIntent.putExtra("rrule", "FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH"); startActivity(calIntent); } ); var COLS = new[] { "title", "dtstart" }; var at = new TextView(this).AttachTo(ll); at.setText("at " + CalendarContract.Events.CONTENT_URI.ToString()); // from t in calendars // select t.title var mCursor = this.getContentResolver().query( CalendarContract.Events.CONTENT_URI, COLS, null, null, null ); mCursor.moveToLast(); var tv = new TextView(this).AttachTo(ll); tv.setText("n/a"); Action update = delegate { var title = ""; var start = ""; var w = ""; //Format df = android.text.format.DateFormat.getDateFormat(this); //Format tf = android.text.format.DateFormat.getTimeFormat(this); //try //{ title = mCursor.getString(0); start = ((object)mCursor.getLong(1)).ToString(); w += title; w += " at "; w += start; tv.setText(w); //} //catch //{ // tv.setText("n/a error"); // throw; //} }; Button prev, next = null; prev = new Button(this) .WithText("Prev") .AttachTo(ll) .AtClick( b => { if (!mCursor.isFirst()) { mCursor.moveToPrevious(); next.setEnabled(true); } else b.setEnabled(false); update(); } ); next = new Button(this) .WithText("Next") .AttachTo(ll) .AtClick( b => { if (!mCursor.isLast()) { mCursor.moveToNext(); prev.setEnabled(true); } else b.setEnabled(false); update(); } ); update(); this.setContentView(sv); }
static ApplicationWebService() { #if Android Console.WriteLine("ApplicationWebService cctor"); if (__AndroidMulticast.value == null) { // Acquire multicast lock wifi = (WifiManager) ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext.getSystemService(Context.WIFI_SERVICE); multicastLock = wifi.createMulticastLock("multicastLock"); // ? //multicastLock.setReferenceCounted(true); multicastLock.acquire(); __AndroidMulticast.value = new __AndroidMulticast( value => { Console.WriteLine( "ApplicationWebService cctor: " + new { value } ); #region NotifyService try { var xml = XElement.Parse(value); // ApplicationWebService cctor: { value = <string reason="shake" c="8" preview="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAIAAABt+uBvAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAUBklEQVR4nN2dz5Mkx1XHv+9lVlX/mJ0fuzuS1kZCksMmrPCBCAEHMBEcIYAjEQQHgiB84z/hxh3wCQIHdoAPcMIYcAAH47BDQsi2tLJWsqwf+2tmdrq7qrIyH4eszM6q6p6d6dmetf2itre6uioz65PffJn56sfQi/v72NQa5x4uFjNjNk5he1YodWMyyZW6ZDpqfzTa4DABHlXV3fm8tvaSJdiSWZGZMUSUa02XSGcTQJW1d2ez07qWS2R8BSbAommMtaMsY9qQ0sUAichxVd1fLBrnNsvv6s04tzBmpLVi3uDwix1TNs1RWYr8lEunb8a5j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51fcW2FUCUBDcORqMb4/GiWV4RE5G78/mF/uhWxnxUlk+F0f8Du/6q+dpYHY8AAAAASUVORK5CYII=" n="com.abstractatech.gamification.gir">Visit me at 192.168.43.7:25814</string> } Console.WriteLine(new { xml }); // I/System.Console( 7351): ApplicationWebService cctor: { value = <string c="1">Visit me at 192.168.43.252:25452</string> } ApplicationWebServiceExtensions.History.Add( xml ); var uri = "http://visit.jsc-solutions.net"; if (xml.Value.StartsWith("Visit me at ")) uri = "http://" + xml.Value.Substring("Visit me at ".Length); #region intent var c = ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext; var intent = new Intent(c, typeof(foo.NotifyService).ToClass()); intent.putExtra("data0", "Another application running"); intent.putExtra("data1", uri); c.startService(intent); #endregion } catch (Exception ex) { // client error System.Console.WriteLine( "ApplicationWebService cctor error " + new { ex.Message, ex.StackTrace } ); } #endregion // http://grepcode.com/file/repository.springsource.com/org.apache.xalan/com.springsource.org.apache.xml.serializer/2.7.1/org/apache/xml/serializer/ToStream.java#2099 } ); } #endif }
// https://github.com/opersys/raidl // 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 // https://github.com/android/platform_frameworks_base/blob/master/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java //AtBootCompleted hack1; protected override void onCreate(global::android.os.Bundle savedInstanceState) { // 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); #region startservice var startservice = new Button(this); startservice.setText("Start Service to send Notification"); startservice.AtClick( delegate { startservice.setEnabled(false); //this.ShowToast("startservice_onclick"); //var intent = new Intent(this, NotifyService.Class); var intent = new Intent(this, typeof(NotifyService).ToClass()); this.startService(intent); // http://developer.android.com/reference/android/app/Activity.html#recreate%28%29 this.recreate(); } ); ll.addView(startservice); #endregion #region stopservice var stopservice = new Button(this); stopservice.setText("Stop Service"); stopservice.AtClick( delegate { this.ShowToast("stopservice_onclick"); var intent = new Intent(); intent.setAction(NotifyService.ACTION); intent.putExtra("RQS", NotifyService.RQS_STOP_SERVICE); this.sendBroadcast(intent); // seems stop takes a while //Task.Delay(100); Thread.Sleep(30); this.recreate(); } ); ll.addView(stopservice); #endregion stopservice.setEnabled(false); // http://stackoverflow.com/questions/12891903/android-check-if-my-service-is-running-in-the-background var m = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE); Console.WriteLine("getRunningServices"); var s = m.getRunningServices(1000); Console.WriteLine("getRunningServices " + s.size()); var se = // http://stackoverflow.com/questions/7170730/how-to-set-a-control-panel-for-my-service-in-android from i in Enumerable.Range(0, s.size()) let rsi = (android.app.ActivityManager.RunningServiceInfo)s.get(i) let cn = rsi.service.getClassName() let cp = m.getRunningServiceControlPanel(rsi.service) //orderby cn orderby cp != null select new { i, rsi, cn, cp }; //java.lang.JavaSystem.ex // I/System.Console( 1617): { i = 45, cn = android.hardware.location.GeofenceHardwareService, cp = } //I/System.Console( 1617): { i = 17, cn = ccc71.at.services.at_service, cp = } //I/System.Console( 1617): { i = 34, cn = com.android.bluetooth.a2dp.A2dpService, cp = } //I/System.Console( 1617): { i = 13, cn = com.android.bluetooth.btservice.AdapterService, cp = } //I/System.Console( 1617): { i = 23, cn = com.android.bluetooth.gatt.GattService, cp = } //I/System.Console( 1617): { i = 68, cn = com.android.bluetooth.hfp.HeadsetService, cp = } //I/System.Console( 1617): { i = 0, cn = com.android.bluetooth.hid.HidService, cp = } //I/System.Console( 1617): { i = 84, cn = com.android.bluetooth.pan.PanService, cp = } //I/System.Console( 1617): { i = 80, cn = com.android.defcontainer.DefaultContainerService, cp = } //I/System.Console( 1617): { i = 37, cn = com.android.incallui.InCallServiceImpl, cp = } //I/System.Console( 1617): { i = 71, cn = com.android.incallui.MCIDService, cp = } //I/System.Console( 1617): { i = 55, cn = com.android.incallui.SecInCallService, cp = } //I/System.Console( 1617): { i = 73, cn = com.android.internal.backup.LocalTransportService, cp = } //I/System.Console( 1617): { i = 81, cn = com.android.phone.TelephonyDebugService, cp = } //I/System.Console( 1617): { i = 66, cn = com.android.providers.media.MtpService, cp = } //I/System.Console( 1617): { i = 65, cn = com.android.server.DrmEventService, cp = } //I/System.Console( 1617): { i = 57, cn = com.android.server.telecom.BluetoothPhoneService, cp = } //I/System.Console( 1617): { i = 50, cn = com.android.server.telecom.BluetoothVoIPService, cp = } //I/System.Console( 1617): { i = 62, cn = com.android.stk.StkAppService, cp = } //I/System.Console( 1617): { i = 15, cn = com.android.systemui.ImageWallpaper, cp = PendingIntent{2759cef2: android.os.BinderProxy@181ef173} } //I/System.Console( 1617): { i = 44, cn = com.android.systemui.SystemUIService, cp = } //I/System.Console( 1617): { i = 12, cn = com.android.systemui.keyguard.KeyguardService, cp = } //I/System.Console( 1617): { i = 21, cn = com.dsi.ant.server.AntService, cp = } //I/System.Console( 1617): { i = 48, cn = com.fmm.dm.XDMService, cp = } //I/System.Console( 1617): { i = 22, cn = com.google.android.gms.analytics.service.AnalyticsService, cp = } //I/System.Console( 1617): { i = 51, cn = com.google.android.gms.auth.trustagent.GoogleTrustAgent, cp = } //I/System.Console( 1617): { i = 86, cn = com.google.android.gms.backup.BackupTransportService, cp = } //I/System.Console( 1617): { i = 4, cn = com.google.android.gms.car.CarService, cp = } //I/System.Console( 1617): { i = 76, cn = com.google.android.gms.clearcut.service.ClearcutLoggerService, cp = } //I/System.Console( 1617): { i = 75, cn = com.google.android.gms.common.stats.GmsCoreStatsService, cp = } //I/System.Console( 1617): { i = 67, cn = com.google.android.gms.deviceconnection.service.DeviceConnectionServiceBroker, cp = } //I/System.Console( 1617): { i = 19, cn = com.google.android.gms.gcm.GcmService, cp = } //I/System.Console( 1617): { i = 38, cn = com.google.android.gms.gcm.http.GoogleHttpService, cp = } //I/System.Console( 1617): { i = 74, cn = com.google.android.gms.playlog.service.PlayLogBrokerService, cp = } //I/System.Console( 1617): { i = 18, cn = com.google.android.gms.trustagent.api.trustagent.GoogleTrustAgentService, cp = } //I/System.Console( 1617): { i = 25, cn = com.google.android.gms.usagereporting.service.UsageReportingService, cp = } //I/System.Console( 1617): { i = 82, cn = com.google.android.gms.wearable.service.WearableService, cp = } //I/System.Console( 1617): { i = 40, cn = com.google.android.hotword.service.HotwordService, cp = } //I/System.Console( 1617): { i = 60, cn = com.google.android.libraries.hangouts.video.VideoChatService, cp = } //I/System.Console( 1617): { i = 30, cn = com.google.android.location.fused.FusedLocationService, cp = } //I/System.Console( 1617): { i = 16, cn = com.google.android.location.geocode.GeocodeService, cp = } //I/System.Console( 1617): { i = 39, cn = com.google.android.location.geofencer.service.GeofenceProviderService, cp = } //I/System.Console( 1617): { i = 63, cn = com.google.android.location.internal.GoogleLocationManagerService, cp = } //I/System.Console( 1617): { i = 54, cn = com.google.android.location.internal.PendingIntentCallbackService, cp = } //I/System.Console( 1617): { i = 58, cn = com.google.android.location.internal.server.GoogleLocationService, cp = } //I/System.Console( 1617): { i = 61, cn = com.google.android.location.network.NetworkLocationService, cp = } //I/System.Console( 1617): { i = 3, cn = com.google.android.music.dial.DialMediaRouteProviderService, cp = } //I/System.Console( 1617): { i = 6, cn = com.google.android.search.core.service.BroadcastListenerService, cp = } //I/System.Console( 1617): { i = 35, cn = com.google.android.search.core.service.SearchService, cp = } //I/System.Console( 1617): { i = 69, cn = com.google.android.voiceinteraction.GsaVoiceInteractionService, cp = } //I/System.Console( 1617): { i = 85, cn = com.ime.framework.spellcheckservice.SamsungIMESpellCheckerService, cp = } //I/System.Console( 1617): { i = 49, cn = com.samsung.android.MtpApplication.MtpService, cp = } //I/System.Console( 1617): { i = 78, cn = com.samsung.android.app.catchfavorites.catchnotifications.CatchNotificationsService, cp = PendingIntent{1f770943: android.os.BinderProxy@6924ca9} } //I/System.Console( 1617): { i = 56, cn = com.samsung.android.app.edge.nightclock.NightClockService, cp = } //I/System.Console( 1617): { i = 59, cn = com.samsung.android.app.galaxyfinder.recommended.RecommendedService, cp = } //I/System.Console( 1617): { i = 53, cn = com.samsung.android.app.galaxyfinder.tag.TagReadyService, cp = } //I/System.Console( 1617): { i = 72, cn = com.samsung.android.app.shealth.tracker.pedometer.service.PedometerService, cp = } //I/System.Console( 1617): { i = 32, cn = com.samsung.android.app.shealth.tracker.sport.livetracker.LiveTrackerService, cp = } //I/System.Console( 1617): { i = 79, cn = com.samsung.android.beaconmanager.BeaconService, cp = } //I/System.Console( 1617): { i = 42, cn = com.samsung.android.health.wearable.service.WearableService, cp = } //I/System.Console( 1617): { i = 70, cn = com.samsung.android.providers.context.ContextService, cp = } //I/System.Console( 1617): { i = 24, cn = com.samsung.android.scloud.auth.RelayService, cp = } //I/System.Console( 1617): { i = 26, cn = com.samsung.android.sconnect.periph.PeriphService, cp = } //I/System.Console( 1617): { i = 29, cn = com.samsung.android.sensor.framework.SensorService, cp = } //I/System.Console( 1617): { i = 64, cn = com.samsung.android.service.health.HealthService, cp = } //I/System.Console( 1617): { i = 14, cn = com.samsung.android.service.peoplestripe.PeopleNotiListenerService, cp = PendingIntent{17538bc0: android.os.BinderProxy@6924ca9} } //I/System.Console( 1617): { i = 77, cn = com.samsung.android.service.peoplestripe.PeopleStripeService, cp = } //I/System.Console( 1617): { i = 28, cn = com.samsung.android.sm.widgetapp.SMWidgetService, cp = } //I/System.Console( 1617): { i = 47, cn = com.samsung.android.thememanager.ThemeManagerService, cp = } //I/System.Console( 1617): { i = 52, cn = com.samsung.appcessory.server.SAPService, cp = } //I/System.Console( 1617): { i = 5, cn = com.samsung.hs20settings.WifiHs20UtilityService, cp = } //I/System.Console( 1617): { i = 41, cn = com.samsung.sec.android.application.csc.CscUpdateService, cp = } //I/System.Console( 1617): { i = 2, cn = com.sec.android.app.bluetoothtest.BluetoothBDTestService, cp = } //I/System.Console( 1617): { i = 31, cn = com.sec.android.app.launcher.services.LauncherService, cp = } //I/System.Console( 1617): { i = 10, cn = com.sec.android.daemonapp.ap.accuweather.WeatherClockService, cp = } //I/System.Console( 1617): { i = 8, cn = com.sec.android.inputmethod.SamsungKeypad, cp = PendingIntent{39a730f9: android.os.BinderProxy@2b45775c} } //I/System.Console( 1617): { i = 46, cn = com.sec.android.pagebuddynotisvc.PageBuddyNotiSvc, cp = } //I/System.Console( 1617): { i = 1, cn = com.sec.android.sensor.framework.SensorService, cp = } //I/System.Console( 1617): { i = 83, cn = com.sec.android.service.sm.service.SecurityManagerService, cp = } //I/System.Console( 1617): { i = 7, cn = com.sec.android.widgetapp.ap.weather.common.appservice.WeatherScreenService, cp = } //I/System.Console( 1617): { i = 11, cn = com.sec.android.widgetapp.ap.weather.common.appservice.WeatherService, cp = } //I/System.Console( 1617): { i = 36, cn = com.sec.android.widgetapp.ap.weather.widget.surfacewidget.WeatherSurfaceWidget, cp = } //I/System.Console( 1617): { i = 33, cn = com.sec.android.widgetapp.digitalclockeasy.DigitalClockEasyService, cp = } //I/System.Console( 1617): { i = 9, cn = com.sec.bcservice.BroadcastService, cp = } //I/System.Console( 1617): { i = 20, cn = com.sec.enterprise.mdm.services.simpin.EnterpriseSimPin, cp = } //I/System.Console( 1617): { i = 87, cn = com.sec.phone.SecPhoneService, cp = } //I/System.Console( 1617): { i = 43, cn = com.sec.spp.push.PushClientService, cp = } //I/System.Console( 1617): { i = 27, cn = org.simalliance.openmobileapi.service.SmartcardService, cp = } //I/System.Console( 5883): { i = 85, cn = com.google.android.gms.backup.BackupTransportService, process = com.google.android.gms.persistent } //I/System.Console( 5883): { i = 86, cn = com.sec.phone.SecPhoneService, process = com.sec.phone } //I/System.Console( 5883): { i = 7, cn = com.sec.android.inputmethod.SamsungKeypad, process = com.sec.android.inputmethod, cp = PendingIntent{e6c79e2: android.os.BinderProxy@181ef173}, describeContents = 0 } //I/System.Console( 5883): { i = 13, cn = com.samsung.android.service.peoplestripe.PeopleNotiListenerService, process = com.samsung.android.service.peoplestripe, cp = PendingIntent{24b00830: android.os.BinderProxy@6924ca9}, describeContents = 0 } //I/System.Console( 5883): { i = 14, cn = com.android.systemui.ImageWallpaper, process = com.android.systemui.imagewallpaper, cp = PendingIntent{135c522e: android.os.BinderProxy@1ced31cf}, describeContents = 0 } //I/System.Console( 5883): { i = 77, cn = com.samsung.android.app.catchfavorites.catchnotifications.CatchNotificationsService, process = com.samsung.android.app.catchfavorites, cp = PendingIntent{2b45775c: android.os.BinderProxy@6924ca9}, describeContents = 0 } // http://stackoverflow.com/questions/7170730/how-to-set-a-control-panel-for-my-service-in-android // The service's description and configuration intent can be set during a service binding foreach (var ss in se) { var cn = ss.cn; PendingIntent cp = ss.cp; // whats a ControlPanel ? // Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.app.PendingIntent.describeContents()' on a null object reference if (cp == null) Console.WriteLine(new { ss.i, cn, ss.rsi.process }); else Console.WriteLine(new { ss.i, cn, ss.rsi.process, cp, describeContents = cp.describeContents() }); // I/System.Console(17713): { cn = AndroidBootServiceNotificationActivity.Activities.NotifyService } if (cn == typeof(NotifyService).FullName) { // cannot find ourself? unless its running startservice.setEnabled(false); stopservice.setEnabled(true); // its running // http://stackoverflow.com/questions/7170730/how-to-set-a-control-panel-for-my-service-in-android // http://www.techques.com/question/1-7170730/How-to-set-a-control-panel-for-my-Service-in-Android // http://alvinalexander.com/java/jwarehouse/android/core/java/android/app/ActivityManagerNative.java.shtml } #region cp if (cp != null) { // could we not infer activity from code from application? new Button(this).WithText( cn ).AtClick( delegate { // http://codetheory.in/android-pending-intents/ try { cp.send(); } catch { } //this.startActivity( // cp //); } ).AttachTo(ll); } #endregion } this.setContentView(sv); //this.ShowToast("http://jsc-solutions.net"); new Button(this).WithText("exit").AttachTo(ll).AtClick( delegate { // will it be logged? System.Environment.Exit(13); // application still visible in tasks? } ); new Button(this).WithText("finish").AttachTo(ll).AtClick( delegate { //this.finishAndRemoveTask(); this.finish(); // will it be logged? //System.Environment.Exit(13); // application still visible in tasks? } ); new Button(this).WithText("finishAndRemoveTask").AttachTo(ll).AtClick( delegate { this.finishAndRemoveTask(); //this.finish(); // will it be logged? //System.Environment.Exit(13); // application still visible in tasks? } ); }
// "x:\util\android-sdk-windows\platform-tools\adb.exe" connect 192.168.1.126:5555 // x:\util\android-sdk-windows\platform-tools\adb.exe logcat -s "xNativeActivity" "System.Console" "DEBUG" // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201505/20150513 // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201505/20150531 // 01. lets have our service think of a port, and send it back to activity at start. or save into file as cpu does it? // http://developer.android.com/reference/android/os/MemoryFile.html // http://stackoverflow.com/questions/19778196/class-memoryfile-of-any-use // http://stackoverflow.com/questions/15123402/share-memory-between-two-processes-in-dalvik // http://www.slideshare.net/tetsu.koba/interprocess-communication-of-android // http://www.codota.com/android/scenarios/52fcbca7da0a12229fc989b1/android.os.MemoryFile?tag=dragonfly // https://groups.google.com/forum/#!topic/android-developers/r-oqeI7MlJg // http://stackoverflow.com/questions/19778196/class-memoryfile-of-any-use // https://vec.io/posts/andriod-ipc-shared-memory-with-ashmem-memoryfile-and-binder // http://notjustburritos.tumblr.com/post/21442138796/an-introduction-to-android-shared-memory // https://developer.android.com/training/articles/memory.html // http://www.slideshare.net/jserv/android-ipc-mechanism //Action AtActivityResult; //protected override void onActivityResult(int arg0, int arg1, Intent arg2) //{ // base.onActivityResult(arg0, arg1, arg2); // if (AtActivityResult != null) // AtActivityResult(); //} // I/ActivityManager( 475): Killing 7649:AndroidMultiProcTCPServerAsync.Activities/u0a49 (adj 9): remove task //I/ActivityManager( 475): Killing 7627:AndroidMultiProcTCPServerAsync.Activities:gateway7/u0a49 (adj 5): remove task //I/ActivityManager( 475): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.l //W/ActivityManager( 475): Scheduling restart of crashed service AndroidMultiProcTCPServerAsync.Activities/.GatewayService in 16000ms //protected override void onPause() //{ // Console.WriteLine("enter onPause, finishAndRemoveTask"); // // not called on back button? // // keep service running, remove activity // this.finishAndRemoveTask(); // base.onPause(); //} protected override void onCreate(Bundle savedInstanceState) { base.onCreate(savedInstanceState); var sv = new ScrollView(this); var ll = new LinearLayout(this); // fill the button ll.setOrientation(LinearLayout.VERTICAL); sv.addView(ll); this.setContentView(sv); var activity = this; new Button(activity).WithText("is the service already running?").AttachTo(ll); var m = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE); // why limit? var s = m.getRunningServices(0xffff); var a = Enumerable.FirstOrDefault( from i in Enumerable.Range(0, s.size()) let rsi = (android.app.ActivityManager.RunningServiceInfo)s.get(i) let cn = rsi.service.getClassName() where cn == typeof(GatewayService).FullName select new { i, rsi, cn } ); if (a == null) { new Button(activity).WithText("start service").AttachTo(ll).AtClick( delegate { // start the service unless already running? var intent = new Intent(this.getApplicationContext(), typeof(GatewayService).ToClass()); // if the user can swipe us away service is restarted? this.getApplicationContext().startService(intent); } ); } else { } // whats the port? new Button(activity).WithText("which port are we on? " + new { a }).AttachTo(ll).AtClick( delegate { var aa = default(AsyncReplyReceiver); aa = new AsyncReplyReceiver { AtReceive = (cc, ii) => { Console.WriteLine("ui now has the port..."); this.unregisterReceiver(aa); var host = ii.getStringExtra("host"); var port = ii.getIntExtra("port", 0); new Button(activity).WithText("open " + host + ":" + port).AttachTo(ll).AtClick( delegate { var href = "http://" + host + ":" + port; Console.WriteLine( href ); //this.runOnUiThread( // delegate // { var i = new Intent(Intent.ACTION_VIEW, android.net.Uri.parse(href) ); // http://vaibhavsarode.wordpress.com/2012/05/14/creating-our-own-activity-launcher-chooser-dialog-android-launcher-selection-dialog/ var ic = Intent.createChooser(i, href); this.startActivity(ic); // } //); } ); } }; var intentFilter = new IntentFilter(); intentFilter.addAction(GatewayService.ACTION + "reply"); this.registerReceiver(aa, intentFilter); var intent = new Intent(); intent.setAction(GatewayService.ACTION); intent.putExtra("whats my port", "?"); this.sendBroadcast(intent); } ); new Button(this).WithText("exit").AttachTo(ll).AtClick( delegate { // will it be logged? System.Environment.Exit(13); // application still visible in tasks? } ); new Button(this).WithText("finish").AttachTo(ll).AtClick( delegate { //this.finishAndRemoveTask(); this.finish(); // will it be logged? //System.Environment.Exit(13); // application still visible in tasks? } ); new Button(this).WithText("finishAndRemoveTask").AttachTo(ll).AtClick( delegate { this.finishAndRemoveTask(); //this.finish(); // will it be logged? //System.Environment.Exit(13); // application still visible in tasks? } ); // [javac] W:\src\AndroidMultiProcTCPServerAsync\Activities\ApplicationActivity.java:56: error: unreported exception IOException; must be caught or declared to be thrown //[javac] class22.m = new MemoryFile("foo0", 100); //// ipc memory referenced //var m = default(MemoryFile); //try //{ // m = new MemoryFile("foo0", 100); //} //catch { throw; } // MemoryFile not available yet. bypass to NDK? workaround to filesystem? // E/AndroidRuntime(28716): Caused by: android.system.ErrnoException: open failed: EROFS (Read-only file system) // http://developer.android.com/training/basics/data-storage/files.html // File.WriteAllText(this.getFilesDir().getAbsolutePath() + "/MemoryFile-foo0", "awaiting..."); // new Button(activity).WithText("Next " + // File.ReadAllText(this.getFilesDir().getAbsolutePath() + "/MemoryFile-foo0") // ).AttachTo(ll).AtClick( // button => // { // Intent intent = new Intent(activity, typeof(SecondaryActivity).ToClass()); // intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); // // share scope // var myPid = android.os.Process.myPid(); // intent.putExtra("_item", "hello from " + new { myPid }); // //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); // //new Button(activity).WithText("read").AttachTo(ll).AtClick( // // button2 => // // { // // var m2 = default(MemoryFile); // // try // // { // // m2 = new MemoryFile("foo0", 100); // // } // // catch { throw; } // // var pos = 0; // // //var __out = new __NetworkStream { InternalOutputStream = m.getOutputStream() }; // // var __in = new __NetworkStream { InternalInputStream = m2.getInputStream() }; // // // block the ui? // // var ipcByte = 0; // // while (ipcByte == 0) // // { // // ipcByte = __in.ReadByte(); // // button2.WithText(new { ipcByte, pos }.ToString()); // // pos++; // // } // // } // // ); // AtActivityResult += // delegate // { // // if we read too early we get all zeros.. // //var pos = 0; // ////var __out = new __NetworkStream { InternalOutputStream = m.getOutputStream() }; // //var __in = new __NetworkStream { InternalInputStream = m.getInputStream() }; // //// block the ui? // //var ipcByte = 0; // //while (ipcByte == 0) // //{ // // ipcByte = __in.ReadByte(); // // button.WithText(new { ipcByte, pos }.ToString()); // // pos++; // //} // button.WithText( // File.ReadAllText(this.getFilesDir().getAbsolutePath() + "/MemoryFile-foo0") // ); // }; // // cached backgroun process? // // switching to another process.. easy... // //activity.startActivity(intent); // activity.startActivityForResult(intent, requestCode: 0x14); // } //); // //var s = new SemaphoreSlim(0); // ////java.lang.Object, rt // ////enter async { ManagedThreadId = 1 } // ////awaiting for SemaphoreSlim{ ManagedThreadId = 1 } // ////after delay{ ManagedThreadId = 8 } // ////http://127.0.0.1:8080 // ////{ fileName = http://127.0.0.1:8080 } // ////enter catch { mname = <0032> nop.try } ClauseCatchLocal: // ////{ Message = , StackTrace = java.lang.RuntimeException // //// at ScriptCoreLibJava.BCLImplementation.System.Net.Sockets.__TcpListener.AcceptTcpClientAsync(__TcpListener.java:131) // //new { }.With( // // async delegate // // { // // //System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 // // //enter async { ManagedThreadId = 1 } // // //awaiting for SemaphoreSlim{ ManagedThreadId = 1 } // // //after delay{ ManagedThreadId = 4 } // // //http://127.0.0.1:8080 // // //awaiting for SemaphoreSlim. done.{ ManagedThreadId = 1 } // // //-- // // //accept { c = System.Net.Sockets.TcpClient, ManagedThreadId = 6 } // // //System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 // // //accept { c = System.Net.Sockets.TcpClient, ManagedThreadId = 8 } // // //{ ManagedThreadId = 6, input = GET / HTTP/1.1 // // // jump back to main thread.. // // s.Release(); // // } // //); }
// test via // X:\jsc.svn\examples\javascript\chrome\apps\ChromeUDPSendAsync\ChromeUDPSendAsync\Application.cs // how do we know its running? // x:\util\android-sdk-windows\platform-tools\adb.exe logcat -s "DEBUG" "System.Console" // "x:\util\android-sdk-windows\platform-tools\adb.exe" connect 192.168.1.126:5555 // https://github.com/opersys/raidl // 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 //AtBootCompleted hack1; protected override void onCreate(global::android.os.Bundle savedInstanceState) { // 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); #region startservice var startservice = new Button(this); startservice.setText("Start Service"); startservice.AtClick( delegate { startservice.setEnabled(false); //this.ShowToast("startservice_onclick"); //var intent = new Intent(this, NotifyService.Class); var intent = new Intent(this, typeof(NotifyService).ToClass()); this.startService(intent); // http://developer.android.com/reference/android/app/Activity.html#recreate%28%29 //this.recreate(); this.finish(); } ); ll.addView(startservice); #endregion #region stopservice var stopservice = new Button(this); stopservice.setText("Stop Service"); stopservice.AtClick( delegate { this.ShowToast("stopservice_onclick"); var intent = new Intent(); intent.setAction(NotifyService.ACTION); intent.putExtra("RQS", NotifyService.RQS_STOP_SERVICE); this.sendBroadcast(intent); // seems stop takes a while //Task.Delay(100); Thread.Sleep(30); this.recreate(); } ); ll.addView(stopservice); #endregion stopservice.setEnabled(false); // http://stackoverflow.com/questions/12891903/android-check-if-my-service-is-running-in-the-background var m = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE); Console.WriteLine("getRunningServices"); var s = m.getRunningServices(1000); Console.WriteLine("getRunningServices " + s.size()); var se = Enumerable.Range(0, s.size()).Select(i => (android.app.ActivityManager.RunningServiceInfo)s.get(i)); foreach (var ss in se) { var cn = ss.service.getClassName(); Console.WriteLine(new { cn }); // I/System.Console(17713): { cn = AndroidServiceUDPNotification.Activities.NotifyService } if (cn == typeof(NotifyService).FullName) { startservice.setEnabled(false); stopservice.setEnabled(true); // its running // http://stackoverflow.com/questions/7170730/how-to-set-a-control-panel-for-my-service-in-android // http://www.techques.com/question/1-7170730/How-to-set-a-control-panel-for-my-Service-in-Android // http://alvinalexander.com/java/jwarehouse/android/core/java/android/app/ActivityManagerNative.java.shtml #if XCONTROLPANEL PendingIntent cp = m.getRunningServiceControlPanel(ss.service); Console.WriteLine(new { cp }); if (cp != null) { #region cpb var cpb = new Button(this); cpb.setText("ServiceControlPanel"); cpb.AtClick( delegate { //new Intent( //PendingIntent.getActivity( //startActivity(cp); // http://iserveandroid.blogspot.com/2011/03/how-to-launch-pending-intent.html Intent intent = new Intent(); try { cp.send(this, 0, intent); } catch { throw; } } ); ll.addView(cpb); } #endregion #endif } } this.setContentView(sv); this.ShowToast("http://jsc-solutions.net"); }
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); }
protected override void onListItemClick (ListView list, View v, int pos, long id) { Intent intent = new Intent (this, typeof (ImageActivity)); intent.putExtra (EXTRA_POSITION, pos); startActivityForResult (intent, 1); }
public void Launch( string packageName, string name, string ExtraKey = "ExtraKey", string ExtraValue = "ExtraValue" ) { // http://stackoverflow.com/questions/12504954/how-to-start-an-intent-from-a-resolveinfo var c = new ComponentName(packageName, name); Intent i = new Intent(Intent.ACTION_MAIN); i.addCategory(Intent.CATEGORY_LAUNCHER); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); i.setComponent(c); // http://stackoverflow.com/questions/11860074/start-activity-for-result // http://stackoverflow.com/questions/2844440/passing-arguments-from-loading-activity-to-main-activity i.putExtra(ExtraKey, ExtraValue); var context = ThreadLocalContextReference.CurrentContext; context.startActivity(i); }
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; } }
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 }
// gateway service process/ event thread / async enabled? public override int onStartCommand(Intent value0, int flags, int startId) { // Options that have been set in the service declaration in the manifest. // http://developer.android.com/reference/android/content/pm/ServiceInfo.html#FLAG_STOP_WITH_TASK Console.WriteLine("enter onStartCommand " + new { flags, startId }); // until wifi changes? var xipv4 = //from n in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces() from n in AllNetworkInterfaces let IPProperties = n.GetIPProperties() let c = IPProperties.UnicastAddresses.Count from i in Enumerable.Range(0, c) let ip = IPProperties.UnicastAddresses[i] where ip.Address.AddressFamily == AddressFamily.InterNetwork //let loop = IPAddress.Loopback == ip.Address let loop = IPAddress.IsLoopback(ip.Address) orderby loop select new { n, ip, loop, ip.Address }; //I/System.Console(20546): 5042:0001 { n = ScriptCoreLibJava.BCLImplementation.System.Net.NetworkInformation.__NetworkInterface@37e1894a, ip = { Address = 192.168.1.126 }, loop = false, Address = 192.168.1.126 } //I/System.Console(20546): 5042:0001 { n = ScriptCoreLibJava.BCLImplementation.System.Net.NetworkInformation.__NetworkInterface@3c1830bb, ip = { Address = 127.0.0.1 }, loop = true, Address = 127.0.0.1 } xipv4.WithEach( Console.WriteLine ); var BestGuessHost = xipv4.FirstOrDefault(); Console.WriteLine(" " + new { BestGuessHost }); //var port = new Random().Next(8000, 30000); // cached by cloudflare? //var port = 80; var port = 8080; // https://github.com/NanoHttpd/nanohttpd/blob/master/core/src/main/java/fi/iki/elonen/NanoHTTPD.java var notifyServiceReceiver = new AsyncReplyReceiver { AtReceive = (cc, ii) => { Console.WriteLine("enter onReceive"); //android.content.IntentFilter //android.content.Intent.ACTION_BOOT_COMPLETED int rqs = ii.getIntExtra("RQS", 0); if (rqs == RQS_STOP_SERVICE) this.stopSelf(); if (ii.hasExtra("whats my port")) { // how do we reply? // sharedmemory implementation is missing and useless xipv4.WithEach( Console.WriteLine ); var intent = new Intent(); //intent.putExtra("host", BestGuessHost.Address.ToString()); // did we switch networks? intent.putExtra("host", xipv4.FirstOrDefault().ToString()); intent.putExtra("port", port); intent.setAction(GatewayService.ACTION + "reply"); this.sendBroadcast(intent); } } }; #region AtDestroy this.AtDestroy = delegate { Console.WriteLine("enter AtDestroy"); this.unregisterReceiver(notifyServiceReceiver); // I/System.Console( 8080): onDestroy { xmyPid = 8080 } //I/art ( 8080): System.exit called, status: 42 var xmyPid = android.os.Process.myPid(); Console.WriteLine("onDestroy " + new { xmyPid }); System.Environment.Exit(42); }; #endregion //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 2, Name = ip6tnl0, Description = ip6tnl0, SupportsMulticast = false, InetAddressesString = } //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 2, Name = rmnet4, Description = rmnet4, SupportsMulticast = true, InetAddressesString = } //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 2, Name = rmnet2, Description = rmnet2, SupportsMulticast = true, InetAddressesString = } //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 2, Name = rmnet3, Description = rmnet3, SupportsMulticast = true, InetAddressesString = } //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 2, Name = rmnet7, Description = rmnet7, SupportsMulticast = true, InetAddressesString = } //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 2, Name = rmnet5, Description = rmnet5, SupportsMulticast = true, InetAddressesString = } //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 2, Name = rmnet6, Description = rmnet6, SupportsMulticast = true, InetAddressesString = } //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 2, Name = rmnet1, Description = rmnet1, SupportsMulticast = true, InetAddressesString = } //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 2, Name = rmnet0, Description = rmnet0, SupportsMulticast = true, InetAddressesString = } //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 1, Name = lo, Description = lo, SupportsMulticast = false, InetAddressesString = , ::1%1, 127.0.0.1 } //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 2, Name = sit0, Description = sit0, SupportsMulticast = false, InetAddressesString = } //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 1, Name = p2p0, Description = p2p0, SupportsMulticast = true, InetAddressesString = , fe80::e850:8bff:fe7d:277c%p2p0 } //I/System.Console( 9390): 24ae:0001 { OperationalStatus = 1, Name = wlan0, Description = wlan0, SupportsMulticast = true, InetAddressesString = , 2001:7d0:8414:3001:ea50:8bff:fe7d:277c%13, fe80::ea50:8bff:fe7d:277c%wlan0, 2001:7d0:8414:3001:b421:4790:ede8:826c%13, 192.168.1.126 } //I/System.Console(15259): 3b9b:0001 { OperationalStatus = 1, Name = lo, Description = lo, SupportsMulticast = false, InetAddressesString = , ::1%1, 127.0.0.1 } //I/System.Console(15259): 3b9b:0001 { OperationalStatus = 2, Name = dummy0, Description = dummy0, SupportsMulticast = false, InetAddressesString = } //I/System.Console(15259): 3b9b:0001 { OperationalStatus = 2, Name = sit0, Description = sit0, SupportsMulticast = false, InetAddressesString = } //I/System.Console(15259): 3b9b:0001 { OperationalStatus = 2, Name = ip6tnl0, Description = ip6tnl0, SupportsMulticast = false, InetAddressesString = } //I/System.Console(15259): 3b9b:0001 { OperationalStatus = 1, Name = p2p0, Description = p2p0, SupportsMulticast = true, InetAddressesString = , fe80::10bf:48ff:febe:6b7d%p2p0 } //I/System.Console(15259): 3b9b:0001 { OperationalStatus = 1, Name = wlan0, Description = wlan0, SupportsMulticast = true, InetAddressesString = , 2001:7d0:8414:3001:a06f:6dfe:8dfc:42b8%6, 2001:7d0:8414:3001:12bf:48ff:febe:6b7d%6, fe80::12bf:48ff:febe:6b7d%wlan0, 192.168.1.211 } // I/System.Console(11408): 2c90:0001 { OperationalStatus = 1, Name = rmnet0, Description = rmnet0, SupportsMulticast = true, InetAddressesString = , 83.187.193.24 } //Implementation not found for type import : //type: System.Net.NetworkInformation.UnicastIPAddressInformationCollection //method: System.Net.NetworkInformation.UnicastIPAddressInformation get_Item(Int32) //Did you forget to add the [Script] attribute? //Please double check the signature! // http://stackoverflow.com/questions/14182014/android-oncreate-or-onstartcommand-for-starting-service var myPid = android.os.Process.myPid(); var intentFilter = new IntentFilter(); intentFilter.addAction(ACTION); registerReceiver(notifyServiceReceiver, intentFilter); Func<TcpListener> ctor = delegate { TcpListener x = null; try { Console.WriteLine("774 TcpListener " + new { port }); x = new TcpListener(IPAddress.Any, port); Console.WriteLine("776 TcpListener "); // signal UI service is yet again available //Console.WriteLine("before Start "); // I/System.Console(25817): 64d9:0001 { err = java.lang.RuntimeException: bind failed: EACCES (Permission denied) } x.Start(); Console.WriteLine("782 TcpListener "); } catch (Exception err) { Console.WriteLine(new { err }); System.Environment.Exit(42); } return x; }; #region TcpListener new { }.With( async delegate { //var l = new TcpListener(IPAddress.Any, port); var l = ctor(); var href = "http://127.0.0.1:" + port; Console.WriteLine( href ); while (true) { //Console.WriteLine("before AcceptTcpClientAsync "); var c = await l.AcceptTcpClientAsync(); // time to do firewall or security? //Console.WriteLine("before yield " + new { c }); yield(c); //Console.WriteLine("after yield " + new { c }); } } ); #endregion var onStartCommand_status = base.onStartCommand(value0, flags, startId); Console.WriteLine("exit onStartCommand " + new { onStartCommand_status }); // I/System.Console( 9005): 232d:0001 exit onStartCommand { onStartCommand_status = 1 } return onStartCommand_status; }