【问题标题】:Retrieve shared text through share option list?通过共享选项列表检索共享文本?
【发布时间】:2018-10-08 16:15:34
【问题描述】:

我将如何检索通过 android 中的共享选项列表共享的文本? 这是我正在使用的代码。我基本上是通过从例如谷歌中选择文本来向我的应用程序共享文本,然后右键单击它并单击共享,然后我在那里选择我的应用程序。共享功能运行良好,但我想检索我尝试共享的代码中的实际文本!

[Activity(Label = "TextRecieve", Icon = "@drawable/ic_home", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[IntentFilter(new[] { Intent.ActionSend }, Categories = new[] { Intent.CategoryDefault }, DataMimeType = "image/*", Label = "TextRecieve")]
[IntentFilter(new[] { Intent.ActionSend }, Categories = new[] { Intent.CategoryDefault }, DataMimeType = "text/plain", Label = "TextRecieve")]
[IntentFilter(new[] { Intent.ActionSendMultiple }, Categories = new[] { Intent.CategoryDefault }, DataMimeType = "image/*", Label = "TextRecieve")]


        Intent intent = Intent;
        String action = Intent.Action;
        String type = intent.Type;

        if (Intent.ActionSend.Equals(action) && type != null)
        {
            if ("text/plain".Equals(type))
            {
                // Handle text being sent
                // ...
                // ...
                // ...     

            }
            else if (type.StartsWith("image/"))
            {
                // Handle single image being sent
                // ...
                // ...
                // ...    
            }
        }
        else if (Intent.ActionSendMultiple.Equals(action) && type != null)
        {
            if (type.StartsWith("image/"))
            {
                // Handle multiple images being sent
                // ...
                // ...
                // ...                        
            }
        }
        else
        {
            // Handle other intents, such as being started from the home screen                    
        }

【问题讨论】:

    标签: c# android xamarin xamarin.forms visual-studio-2017


    【解决方案1】:

    您应该在“text/plain”语句中添加它。这将通过指定的 Intent “intent”将您共享的文本拉到您的应用程序中。

    String sharedText = intent.GetStringExtra(Intent.ExtraText);
    

    总代码为

            Intent intent = Intent;
            String action = Intent.Action;
            String type = intent.Type;
    
            if (Intent.ActionSend.Equals(action) && type != null)
            {
                if ("text/plain".Equals(type))
                {
                    // Handle text being sent
                    // ...
                    // ...
                    // ...     
                    String sharedText = intent.GetStringExtra(Intent.ExtraText);
                }
                else if (type.StartsWith("image/"))
                {
                    // Handle single image being sent
                    // ...
                    // ...
                    // ...    
                }
            }
            else if (Intent.ActionSendMultiple.Equals(action) && type != null)
            {
                if (type.StartsWith("image/"))
                {
                    // Handle multiple images being sent
                    // ...
                    // ...
                    // ...                        
                }
            }
            else
            {
                // Handle other intents, such as being started from the home screen                    
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-10
      • 2012-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-14
      • 2019-03-02
      相关资源
      最近更新 更多