【发布时间】:2019-07-30 12:33:06
【问题描述】:
我正在尝试将照片分享到 instagram,但出现“不支持文件格式”或“不支持图像格式”错误。
拜托,谁能帮帮我?
我正在使用 Xamarin 表单,使用 Android 项目的功能,这要归功于通用项目中的 DependencyService。
public bool LaunchApp(string path)
{
bool result = false;
String type = "image/*";
String mediaPath = path;
try
{
// Create the new Intent using the 'Send' action.
Intent share = new Intent(Intent.ActionSend);
var aUri = Uri.Parse(mediaPath);
File media = new File(mediaPath);
// Add the URI to the Intent.
share.PutExtra(Intent.ExtraStream, Uri.FromFile(media));
// Set the MIME type
share.SetType(type);
//var intent = new Intent(Intent.ActionView, aUri);
Xamarin.Forms.Forms.Context.StartActivity(Intent.CreateChooser(share, "Share to"));
result = true;
}
catch (ActivityNotFoundException)
{
result = false;
}
return result;
}
}
path = "/storage/emulated/0/Android/data/com.BlogsterApp_Ambassador.app/files/Pictures/temp/Screenshot_20190728_222104.jpg"(此路径是使用 GetGalleryPhotoAsync() 构建的) {
我也在尝试:
-var aUri = Android.Net.Uri.Parse(new Uri(mediaPath).ToString()); - share.PutExtra(Intent.ExtraStream, aUri);
【问题讨论】:
-
在我看来,该错误与将文件发送到 Instagram 的任何代码相去甚远。您似乎在本地读取文件时遇到问题。专注于这一点可能会更好(编辑您的问题以使其清楚。)可能有更多的人可以帮助阅读本地文件,而不是可以帮助将文件传输到 Instagram。将程序的最终目标作为附加信息提及会有所帮助,但您需要明确说明错误发生的位置。
-
我的程序的最终目标是在 Instagram 上发布照片。我在关注这个例子:instagram.com/developer/mobile-sharing/android-intents 但适应了 Xamarin 表单
-
为了获取我的手机相册的照片,我在 GetGalleryPhotoAsync()) 方法中使用了 Xam.Plugin.Media。 var file = await Plugin.Media.CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions { PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium, }); file.Path 是我的代码示例中的mediaPath
-
这是
.jpg格式造成的吗?如您发布的网站,它只支持照片格式:jpeg, gif, png。
标签: android xamarin xamarin.forms instagram share