问题描述
我编写了一个应用程序,可以将带有图像的消息发送到Twitter。 有用! 我在几种设备上进行了测试,并要求其他人也这样做。 当选择了Twitter朋友时,它甚至还可以用于直接消息。 但是,当选择“直接消息”时,它不起作用。 这迫使用户直接选择一个朋友,而不是通过“直接消息”选择他(这很奇怪),否则该图片将不会被附加。 看看屏幕截图:
这是我的Xamarin Android编程代码。 让我知道如何解决。 当前,所有选项都可以使用,即使选择我的朋友, 但不能选择“直接消息” 。 我还需要告诉我,我希望在推文中看到的Twitter文字没有任何问题。
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(基于意图)的解决方案。
1楼
遗憾的是, 。
如果您能够使用Twitter的私有API,则应该能够将media_id
附加到DM。
但是除此之外,您还不走运。
抱歉。