setFlags() 공개 메소드

public setFlags ( int arg0 ) : global::android.content.Intent
arg0 int
리턴 global::android.content.Intent
예제 #1
0
		public override Intent getLaunchIntentForPackage (string packageName)
		{
			if (!loaded_packages.ContainsKey (packageName))
				return null;

			XobotPackageInfo info = loaded_packages [packageName];

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

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

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

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

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

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


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

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

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

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


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

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



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

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

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

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

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


                    item2.setIntent(
                        ic
                    );
                };

            AtOption +=
                item =>
                {

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

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

            this.setContentView(sv);



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

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

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


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

            vConfigurationChanged(null);
        }
        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

        }
        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
        }
        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);
        }
        public void Install(string filename)
        {
            try
            {
                System.Console.WriteLine("will install " + filename);

                // assets only?
                var context = ThreadLocalContextReference.CurrentContext;

                // extract asset
                var assets = context.getResources().getAssets();

                var s = assets.open(filename);

                var bytes = new sbyte[s.available()];

                var cc = s.read(bytes, 0, bytes.Length);

                System.Console.WriteLine(new { cc });

                var DIRECTORY = android.os.Environment.DIRECTORY_DOWNLOADS;

                var dir = android.os.Environment.getExternalStoragePublicDirectory(DIRECTORY).getAbsolutePath();
                //var dir = android.os.Environment.getDownloadCacheDirectory().getAbsolutePath();

                var apk = dir + "/AndroidListApplicationsUpdate.apk";

                System.Console.WriteLine(new { apk });


                //         Caused by: java.io.FileNotFoundException: /cache/AndroidListApplicationsUpdate.apk: open failed: EACCES (Permission denied)
                //at libcore.io.IoBridge.open(IoBridge.java:416)
                //at java.io.RandomAccessFile.<init>(RandomAccessFile.java:118)
                //at java.io.RandomAccessFile.<init>(RandomAccessFile.java:150)
                //at ScriptCoreLibJava.BCLImplementation.System.IO.__File.WriteAllBytes(__File.java:103)
                //... 18 more

                System.IO.File.WriteAllBytes(apk, (byte[])(object)bytes);

                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(android.net.Uri.fromFile(new File(apk)), "application/vnd.android.package-archive");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // without this flag android returned a intent error!

                context.startActivity(intent);
            }
            catch
            {
                throw;
            }
        }
        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);
        }