Получить общий текст через список параметров общего доступа? - PullRequest
0 голосов
/ 27 апреля 2018

Как мне найти текст, который будет доступен через список параметров общего доступа, который есть в Android? Это мой код, который я использую. Я в основном делюсь текстом с моим приложением, выбрав текст, например, из Google, затем щелкните правой кнопкой мыши по нему и нажмите «Поделиться», и я выберу свое приложение там. Функция обмена работает отлично, но я хочу получить фактический текст в моем коде, которым я пытаюсь поделиться!

[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                    
        }

1 Ответ

0 голосов
/ 27 апреля 2018

Вы должны добавить это в ваше утверждение "text / plain". При этом текст, которым вы делитесь, будет перенаправлен в ваше приложение через указанное намерение «намерение».

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                    
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...