【发布时间】:2017-07-04 18:11:27
【问题描述】:
我编写了一个应用程序,该应用程序可以向 twitter 发送带有附加图像的消息。有用!我在几台设备上对其进行了测试,并要求其他人也这样做。 It even works for a Direct Message when a twitter friend is selected.但是,选择“直接消息”时不起作用。这迫使用户直接选择朋友,而不是通过“直接消息”选择他(这真的很奇怪),否则图片不附加。看看截图吧:
这是我的 Xamarin Android 编程代码。让我知道如何解决它。目前,所有选项都有效,即使选择了我的朋友但不是“直接消息”。我还需要说明,我希望在推文中看到的推文文本没有任何问题。
public bool TweetImage(Bitmap imageToTweet)
{
var messageIntent = context.FindMessageIntent(this.twitterConstants.PackageName);
if (messageIntent == null)
{
return false;
}
string outputFileBMP = SaveBitmap(imageToTweet);
context.Tweet(messageIntent, outputFileBMP, this.twitterConstants.DefaultTwitterText, this.twitterConstants.ChooserMessage);
return true;
}
和
public static Intent FindMessageIntent(this ContextWrapper contextWrapper, params string[] packageNames)
{
Intent wantedIntent = new Intent();
wantedIntent.SetType("text/plain");
var resolveInfos = contextWrapper.PackageManager.QueryIntentActivities(wantedIntent, PackageInfoFlags.MatchDefaultOnly);
var result = (from r in resolveInfos
from p in packageNames
where p == r.ActivityInfo.PackageName
select p).FirstOrDefault();
if (result != null)
{
wantedIntent.SetPackage(result);
return wantedIntent;
}
return null;
}
和
public static void Tweet(this ContextWrapper contextWrapper, Intent messageIntent, string filePath = null, string message = null, string chooserMessage = null)
{
if (filePath != null)
{
using (var file = new Java.IO.File(filePath))
{
messageIntent.PutExtra(Intent.ExtraStream, Android.Net.Uri.FromFile(file));
}
}
if (message != null)
{
messageIntent.PutExtra(Intent.ExtraText, message);
}
if (chooserMessage != null)
{
using (var chooser = Intent.CreateChooser(messageIntent, chooserMessage))
{
contextWrapper.StartActivity(chooser);
}
return;
}
contextWrapper.StartActivity(messageIntent);
}
请注意,我使用的是 Android,需要基于 Android(基于意图)的解决方案。
【问题讨论】:
标签: android twitter xamarin.android