我试图在我的 android 应用程序中为图像创建一个“发布”按钮,该按钮适用于 Facebook 应用程序和电子邮件。
这是我的代码(imagePath 类似于“/sdcard/myapp/image.jpg”
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("image/jpeg");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+imagePath));
sendIntent.putExtra(Intent.EXTRA_TEXT, "Enjoy the photo");
startActivity(Intent.createChooser(sendIntent, "Email:"));
这非常适合发送带有附件的电子邮件,但它不适用于 Facebook 应用程序。
如果我正在使用
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(imagePath));
Facebook 的发布有效 - 但不再发送电子邮件附件。
任何想法都可以为两者做些什么?
最佳答案
如果有人感兴趣......我以间接方式解决了它:
File imageFile = new File(imagePath);
String url = "";
try {
url = Media.insertImage(getContentResolver(), imageFile.getAbsolutePath(), imageFile.getName(), imageFile.getName());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
关于android - 在 Android 中将 ActionChooser 与附件一起用于电子邮件和 Facebook 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3951698/