问题描述
我在我的应用程序创建一个位图,并希望通过电子邮件应用程序或Facebook使用Intent.ACTION_SEND分享。共享窗口打开,Gmail和yahoomail应用程序的图标出现,但没有Facebook或G +!我真的不知道有什么问题。还有一个问题是Gmail应用程序不能附加文件(从位图创建)。我读了几个类似的问题,但我依然放养。请帮助我。
这是我的code分享:
私有静态文件writePhotoPng(位图数据,字符串将pathName){
档案文件=新的文件(将pathName);
尝试 {
file.createNewFile();
//的BufferedOutputStream OS =新的BufferedOutputStream(
//新的FileOutputStream(文件));
FileOutputStream中OS =新的FileOutputStream(文件);
data.com preSS(Bitmap.Com pressFormat.PNG,100,OS);
os.flush();
os.close();
}赶上(例外五){
e.printStackTrace();
}
返回的文件;
}
公共静态无效ShareOnFb(位图共享,活动活动,串Emailsubject的){
意向意图=新的意图(android.content.Intent.ACTION_SEND);
// 编辑:
//!幼稚的错误。下面一行是正确的! intent.setType(图像/ *);
intent.setType(图像/ *);
//将数据添加到意图,接收应用程序将决定如何处理它。
// 电子邮件主题:
如果(Emailsubject的空=&安培;!&安培;!emailSubject.equals()){
intent.putExtra(Intent.EXTRA_SUBJECT,Emailsubject的);
}
intent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(writePhotoPng(份额,temp.png)));
activity.startActivity(Intent.createChooser(意向,分享));
}
在纠正我的幼稚的错误(参见有关编辑的部分),并使用this code段我终于解决了这个问题。
如果有人知道什么 contentValue
使用之间的差异,我的方法,请分享与我。
I create a bitmap in my app and want to share it via email apps or Facebook using Intent.ACTION_SEND.the share window opens and gmail and yahoomail apps icon appear but no facebook or g+! I really doesn't know what's the problem. There is another problem that gmail app cannot attach the file (created from bitmap). I read a few similar questions but still I'm stocked. Help me please.
here is my code for sharing:
private static File writePhotoPng(Bitmap data, String pathName) {
File file = new File(pathName);
try {
file.createNewFile();
// BufferedOutputStream os = new BufferedOutputStream(
// new FileOutputStream(file));
FileOutputStream os = new FileOutputStream(file);
data.compress(Bitmap.CompressFormat.PNG, 100, os);
os.flush();
os.close();
} catch (Exception e) {
e.printStackTrace();
}
return file;
}
public static void ShareOnFb(Bitmap share, Activity activity, String emailSubject){
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
// EDIT:
// !!! childish mistake. below line is correct !!! intent.setType("Image/*");
intent.setType("image/*");
//add data to intent, the receiving app will decide what to do with it.
// email subject:
if (emailSubject != null && !emailSubject.equals("")){
intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
}
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(writePhotoPng(share, "temp.png")));
activity.startActivity(Intent.createChooser(intent, "Share on"));
}
after correcting my childish mistake (see EDIT part in question) and Using this code snippet I finally solved this problem.
if anybody knows whats the difference between using contentValue
and my approach please share that with me.
这篇关于当试图分享影像Facebook并没有出现在共享窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!