【发布时间】: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