示例#1
0
        public Task <bool> ShareLink(string title, string extraText)
        {
            Intent sendIntent = new Intent(Intent.ActionSend);

            sendIntent.SetType("text/plain");
            sendIntent.PutExtra(Intent.ExtraText, extraText);

            Intent        receiver      = new Intent(_context, new InviteIntentReceiver().Class);
            PendingIntent pendingIntent = PendingIntent.GetBroadcast(_context, 0, receiver, PendingIntentFlags.UpdateCurrent);
            var           chooserIntent = Intent.CreateChooser(sendIntent, title ?? string.Empty, pendingIntent.IntentSender);

            IList <ResolveInfo>  resInfo    = _context.PackageManager.QueryIntentActivities(sendIntent, 0);
            List <LabeledIntent> intentList = new List <LabeledIntent>();

            for (int i = 0; i < resInfo.Count; i++)
            {
                ResolveInfo ri          = resInfo.ElementAt(i);
                string      packageName = ri.ActivityInfo.PackageName;
                if (packageName.Contains("com.google.android.apps.messaging"))
                {
                    Intent intent = new Intent();
                    intent.SetComponent(new ComponentName(packageName, ri.ActivityInfo.Name));
                    intent.SetAction(Intent.ActionSend);
                    intent.SetType("text/plain");
                    intent.PutExtra(Intent.ExtraText, extraText);
                    intentList.Add(new LabeledIntent(intent, packageName, ri.LoadLabel(_context.PackageManager), ri.Icon));
                }
                else if (packageName.Contains("com.whatsapp"))
                {
                    Intent intent = new Intent();
                    intent.SetComponent(new ComponentName(packageName, ri.ActivityInfo.Name));
                    intent.SetAction(Intent.ActionSend);
                    intent.SetType("text/plain");
                    intent.PutExtra(Intent.ExtraText, extraText);
                    intentList.Add(new LabeledIntent(intent, packageName, ri.LoadLabel(_context.PackageManager), ri.Icon));
                }
                else if (packageName.Contains("com.google.android.apps.docs"))
                {
                    Intent intent = new Intent();
                    intent.SetComponent(new ComponentName(packageName, ri.ActivityInfo.Name));
                    intent.SetAction(Intent.ActionSend);
                    intent.SetType("text/plain");
                    intent.PutExtra(Intent.ExtraText, extraText);
                    intentList.Add(new LabeledIntent(intent, packageName, ri.LoadLabel(_context.PackageManager), ri.Icon));
                }
            }
            LabeledIntent[] extraIntents = intentList.ToArray();


            chooserIntent.PutExtra(Intent.ExtraInitialIntents, extraIntents);
            chooserIntent.SetFlags(ActivityFlags.ClearTop);
            chooserIntent.SetFlags(ActivityFlags.NewTask);

            _context.StartActivity(chooserIntent);
            return(Task.FromResult(true));
        }
示例#2
0
    public static void Share(string body, string subject, string mimeType = "text/plain", string chooserTitle = "Choose application")
    {
#if UNITY_ANDROID
        //        Debug.LogWarning(Build.VERSION.SDK_INT + " => " + Build.VERSION.CODENAME);
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.SetType(mimeType)
        .PutExtra(Intent.EXTRA_SUBJECT, subject)
        .PutExtra(Intent.EXTRA_TEXT, body);

        var intentList = new List <Intent>();

        var activity = Internal.GetCurrentActivity();
        var pm       = activity.GetPackageManager();
        var resInfo  = pm.QueryIntentActivities(intent, 0);


        for (int i = 0; i < resInfo.Count; i++)
        {
            // Extract the label, append it, and repackage it in a LabeledIntent
            ResolveInfo ri = resInfo[i];

            string packageName = ri.ActivityInfo.PackageName;
            if (packageName.Contains("vkontakte") || packageName.Contains("instagram") || packageName.Contains("skype"))
            {
                Intent newIntent = new Intent(Intent.ACTION_SEND);
                newIntent.SetComponent(new ComponentName(packageName, ri.ActivityInfo.Name));
                newIntent.SetPackage(packageName)
                .PutExtra(Intent.EXTRA_SUBJECT, subject)
                .PutExtra(Intent.EXTRA_TEXT, body)
                .SetType(mimeType);

                intentList.Add(new LabeledIntent(newIntent, packageName, ri.LoadLabel(pm) + " [" + i + "]", ri.Icon));
            }
        }

        Intent intentt = intentList[0];
        intentList.RemoveAt(0);
        Parcelable[] extraIntents = new Parcelable[intentList.Count];

        for (int i = 0; i < intentList.Count; i++)
        {
            extraIntents[i] = intentList[i];
        }

        var chooser = Intent.CreateChooser(intentt, chooserTitle);
        chooser.PutExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
        activity.StartActivity(chooser);
#endif
    }
示例#3
0
            public override Android.Views.View GetView(int position, Android.Views.View convertView, ViewGroup parent)
            {
                Android.Views.View view  = base.GetView(position, convertView, parent);
                ResolveInfo        res   = ActivitiesInfo.ElementAt(position);
                ImageView          image = (ImageView)view.FindViewById(
                    BlazorWebViewService.GetResourceId("intent_listview_icon", AndroidResourceType.Identifier)
                    );

                image.SetImageDrawable(res.LoadIcon(BlazorWebViewService.GetCurrentActivity().PackageManager));
                TextView textview = (TextView)view.FindViewById(
                    BlazorWebViewService.GetResourceId("intent_listview_title", AndroidResourceType.Identifier)
                    );

                textview.Text = res.LoadLabel(BlazorWebViewService.GetCurrentActivity().PackageManager);
                return(view);
            }
示例#4
0
        protected List <IDictionary <String, Object> > GetData()
        {
            var myData = new List <IDictionary <String, Object> > ();

            Intent mainIntent = new Intent(Intent.ActionMain, null);

            mainIntent.AddCategory(Intent.CategorySampleCode);

            PackageManager      pm   = PackageManager;
            IList <ResolveInfo> list = pm.QueryIntentActivities(mainIntent, 0);

            if (null == list)
            {
                return(myData);
            }

            int len = list.Count;

            IDictionary <String, Boolean> entries = new Dictionary <String, Boolean> ();

            for (int i = 0; i < len; i++)
            {
                ResolveInfo info = list [i];

                var labelSeq = info.LoadLabel(pm);

                if ("com.example.monodroid.googleapis.maps" == info.ActivityInfo.ApplicationInfo.PackageName)
                {
                    AddItem(myData, labelSeq.ToString(), ActivityIntent(
                                info.ActivityInfo.ApplicationInfo.PackageName,
                                info.ActivityInfo.Name));
                }
            }

            myData.Sort(delegate(IDictionary <string, object> map1, IDictionary <string, object> map2) {
                return(String.Compare((string)map1 ["title"], (string)map2 ["title"], StringComparison.CurrentCulture));
            });

            return(myData);
        }
示例#5
0
        /**
         * Updates the content of a TextView with description of the enabled
         * accessibility services.
         */
        private void UpdateAccessibilityStateView()
        {
            // The API for getting the enabled accessibility services based on feedback
            // type was Added in ICS. Therefore to be backwards compatible we use the
            // APIs in the support library. Note that if the platform API version is lower
            // and the called API is not available an empty list of services is returned.
            IList <AccessibilityServiceInfo> enabledServices =
                AccessibilityManagerCompat.GetEnabledAccessibilityServiceList(mAccessibilityManager,
                                                                              AccessibilityServiceInfo.FEEDBACK_SPOKEN);

            if (!enabledServices.IsEmpty())
            {
                StringBuilder builder             = new StringBuilder();
                int           enabledServiceCount = enabledServices.Size();
                for (int i = 0; i < enabledServiceCount; i++)
                {
                    AccessibilityServiceInfo service = enabledServices.Get(i);
                    // Some new APIs were Added in ICS for getting more information about
                    // an accessibility service. Again accessed them via the support library.
                    ResolveInfo resolveInfo        = AccessibilityServiceInfoCompat.GetResolveInfo(service);
                    string      serviceDescription = GetString(
                        R.String.accessibility_manager_enabled_service,
                        resolveInfo.LoadLabel(GetPackageManager()),
                        AccessibilityServiceInfoCompat.FeedbackTypeToString(service.FeedbackType),
                        AccessibilityServiceInfoCompat.GetDescription(service),
                        AccessibilityServiceInfoCompat.GetSettingsActivityName(service));
                    builder.Append(serviceDescription);
                }
                mAccessibilityStateView.Text = (builder);
            }
            else
            {
                // Either no services or the platform API version is not high enough.
                mAccessibilityStateView.Text = (GetString(
                                                    R.String.accessibility_manager_no_enabled_services));
            }
        }
        protected List <IDictionary <String, Object> > GetData(string prefix)
        {
            List <IDictionary <String, Object> > myData = new List <IDictionary <String, Object> > ();

            Intent mainIntent = new Intent(Intent.ActionMain, null);

            mainIntent.AddCategory("com.pynting.akvaapp.SUPPORT13_SAMPLE_CODE");

            PackageManager pm   = PackageManager;
            var            list = pm.QueryIntentActivities(mainIntent, 0);

            if (null == list)
            {
                return(myData);
            }

            String[] prefixPath;
            String   prefixWithSlash = prefix;

            if (prefix == "")
            {
                prefixPath = null;
            }
            else
            {
                prefixPath      = prefix.Split('/');
                prefixWithSlash = prefix + "/";
            }

            int len = list.Count();

            IDictionary <String, Boolean> entries = new JavaDictionary <String, Boolean> ();

            for (int i = 0; i < len; i++)
            {
                ResolveInfo info     = list [i];
                var         labelSeq = info.LoadLabel(pm);
                String      label    = labelSeq != null
                                        ? labelSeq.ToString()
                                        : info.ActivityInfo.Name;

                if (prefixWithSlash.Length == 0 || label.StartsWith(prefixWithSlash))
                {
                    String[] labelPath = label.Split('/');

                    String nextLabel = prefixPath == null ? labelPath [0] : labelPath [prefixPath.Length];

                    if ((prefixPath != null ? prefixPath.Length : 0) == labelPath.Length - 1)
                    {
                        AddItem(myData, nextLabel, ActivityIntent(
                                    info.ActivityInfo.ApplicationInfo.PackageName,
                                    info.ActivityInfo.Name));
                    }
                    else
                    {
                        if (entries.ContainsKey(nextLabel))
                        {
                            AddItem(myData, nextLabel, BrowseIntent(prefix == "" ? nextLabel : prefix + "/" + nextLabel));
                            entries [nextLabel] = true;
                        }
                    }
                }
            }

            myData.Sort(sDisplayNameComparator);

            return(myData);
        }
示例#7
0
        protected IList <IMap <string, object> > GetData(string prefix)
        {
            IList <IMap <string, object> > myData = new ArrayList <IMap <string, object> >();

            Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);

            mainIntent.AddCategory("com.example.android.supportv4.SUPPORT4_SAMPLE_CODE");

            PackageManager      pm   = GetPackageManager();
            IList <ResolveInfo> list = pm.QueryIntentActivities(mainIntent, 0);

            if (null == list)
            {
                return(myData);
            }

            string[] prefixPath;
            string   prefixWithSlash = prefix;

            if (prefix.Equals(""))
            {
                prefixPath = null;
            }
            else
            {
                prefixPath      = prefix.Split("/");
                prefixWithSlash = prefix + "/";
            }

            int len = list.Size();

            IMap <string, bool?> entries = new HashMap <string, bool?>();

            for (int i = 0; i < len; i++)
            {
                ResolveInfo   info     = list.Get(i);
                ICharSequence labelSeq = info.LoadLabel(pm);
                string        label    = labelSeq != null
                        ? labelSeq.ToString()
                        : info.ActivityInfo.Name;

                if (prefixWithSlash.Length == 0 || label.StartsWith(prefixWithSlash))
                {
                    string[] labelPath = label.Split("/");

                    string nextLabel = prefixPath == null ? labelPath[0] : labelPath[prefixPath.Length];

                    if ((prefixPath != null ? prefixPath.Length : 0) == labelPath.Length - 1)
                    {
                        AddItem(myData, nextLabel, ActivityIntent(
                                    info.ActivityInfo.ApplicationInfo.PackageName,
                                    info.ActivityInfo.Name));
                    }
                    else
                    {
                        if (entries.Get(nextLabel) == null)
                        {
                            AddItem(myData, nextLabel, BrowseIntent(prefix.Equals("") ? nextLabel : prefix + "/" + nextLabel));
                            entries.Put(nextLabel, true);
                        }
                    }
                }
            }

            Collections.Sort(myData, sDisplayNameComparator);

            return(myData);
        }
示例#8
0
        public Task Show(string TextContents, string ShareMessage)
        {
            // Resources resources =

            Intent emailIntent = new Intent();

            emailIntent.SetAction(Intent.ActionSend);
            // Native email client doesn't currently support HTML, but it doesn't hurt to try in case they fix it
            emailIntent.PutExtra(Intent.ExtraText, Html.FromHtml(TextContents));
            emailIntent.PutExtra(Intent.ExtraSubject, "");
            emailIntent.SetType("message/rfc822");

            Intent sendIntent = new Intent(Intent.ActionSend);

            sendIntent.SetType("text/plain");

            Intent openInChooser = Intent.CreateChooser(emailIntent, "Choose Action");

            var resInfo = Forms.Context.PackageManager.QueryIntentActivities(sendIntent, 0);
            List <LabeledIntent> intentList = new List <LabeledIntent>();

            for (int i = 0; i < resInfo.Count; i++)
            {
                // Extract the label, append it, and repackage it in a LabeledIntent
                ResolveInfo ri          = resInfo[i];
                String      packageName = ri.ActivityInfo.PackageName;
                if (packageName.Contains("android.email"))
                {
                    emailIntent.SetPackage(packageName);
                }
                else if (packageName.Contains("twitter") || packageName.Contains("facebook") || packageName.Contains("mms") || packageName.Contains("android.gm"))
                {
                    Intent intent = new Intent();
                    intent.SetComponent(new ComponentName(packageName, ri.ActivityInfo.Name));
                    intent.SetAction(Intent.ActionSend);
                    intent.SetType("text/plain");
                    if (packageName.Contains("twitter"))
                    {
                        intent.PutExtra(Intent.ExtraText, ShareMessage);
                    }
                    else if (packageName.Contains("facebook"))
                    {
                        // Warning: Facebook IGNORES our text. They say "These fields are intended for users to express themselves. Pre-filling these fields erodes the authenticity of the user voice."
                        // One workaround is to use the Facebook SDK to post, but that doesn't allow the user to choose how they want to share. We can also make a custom landing page, and the link
                        // will show the <meta content ="..."> text from that page with our link in Facebook.
                        intent.PutExtra(Intent.ExtraText, TextContents);
                    }
                    else if (packageName.Contains("mms"))
                    {
                        intent.PutExtra(Intent.ExtraText, TextContents);
                    }
                    else if (packageName.Contains("android.gm"))
                    {                     // If Gmail shows up twice, try removing this else-if clause and the reference to "android.gm" above
                        intent.PutExtra(Intent.ExtraText, Html.FromHtml(TextContents));
                        intent.PutExtra(Intent.ExtraSubject, "");
                        intent.SetType("message/rfc822");
                    }

                    intentList.Add(new LabeledIntent(intent, packageName, ri.LoadLabel(Forms.Context.PackageManager), ri.Icon));
                }
            }

            // convert intentList to array
            LabeledIntent[] extraIntents = intentList.ToArray();
            openInChooser.PutExtra(Intent.ExtraInitialIntents, extraIntents);
            Forms.Context.StartActivity(openInChooser);
            return(null);
        }
示例#9
0
        protected JavaList <IDictionary <String, Object> > GetData(String prefix)
        {
            var myData = new List <IDictionary <String, Object> > ();

            Intent mainIntent = new Intent(Intent.ActionMain, null);

            mainIntent.AddCategory(SampleCategory);

            PackageManager      pm   = PackageManager;
            IList <ResolveInfo> list = (IList <ResolveInfo>)pm.QueryIntentActivities(mainIntent, PackageInfoFlags.Activities);

            if (null == list)
            {
                return(new JavaList <IDictionary <String, Object> > (myData));
            }

            String[] prefixPath;
            String   prefixWithSlash = prefix;

            if (prefix.Equals(""))
            {
                prefixPath = null;
            }
            else
            {
                prefixPath      = prefix.Split('/');
                prefixWithSlash = prefix + "/";
            }

            int len = list.Count;

            IDictionary <String, bool?> entries = new JavaDictionary <String, bool?> ();

            for (int i = 0; i < len; i++)
            {
                ResolveInfo info     = list [i];
                var         labelSeq = info.LoadLabel(pm);
                String      label    = labelSeq != null
                                        ? labelSeq.ToString()
                                                : info.ActivityInfo.Name;

                if (prefixWithSlash.Length == 0 || label.StartsWith(prefixWithSlash))
                {
                    String[] labelPath = label.Split('/');

                    String nextLabel = prefixPath == null ? labelPath [0] : labelPath [prefixPath.Length];

                    if ((prefixPath != null ? prefixPath.Length : 0) == labelPath.Length - 1)
                    {
                        AddItem(myData, nextLabel, ActivityIntent(
                                    info.ActivityInfo.ApplicationInfo.PackageName,
                                    info.ActivityInfo.Name));
                    }
                    else
                    {
                        if (entries [nextLabel] == null)
                        {
                            AddItem(myData, nextLabel, BrowseIntent(prefix.Equals("") ? nextLabel : prefix + "/" + nextLabel));
                            entries [nextLabel] = true;
                        }
                    }
                }
            }

            myData.Sort(sDisplayNameComparator);

            return(new JavaList <IDictionary <String, Object> > (myData));
        }