你好evrybody我试着在信使上分享一个图像,但我不知道为什么我的代码不起作用,我按照官方指南,https://developers.facebook.com/docs/messenger/android 有人可以告诉我为什么doese'nt工作?
public void sendMessage(){
Bitmap adv= takePic(HomeActivity.livelloCurrent.getNumeroLivello());
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
adv.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory()+ File.separator + "temporary_file.jpg");
try {
f.createNewFile();
new FileOutputStream(f).write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
String mimeType = "image/jpeg";
Intent sendIntent = new Intent();
sendIntent.setType(mimeType);
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg"));
sendIntent.putExtra(Intent.EXTRA_TEXT, "<---MY TEXT--->.");
sendIntent.setPackage("com.facebook.orca");
try {
startActivity(sendIntent);
}
catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getApplicationContext(),"Please Install Facebook Messenger", Toast.LENGTH_LONG).show();
}
/** //withSDK-->// ShareToMessengerParams shareToMessengerParams = ShareToMessengerParams.newBuilder(ContentUri, mimeType).build();
MessengerUtils.shareToMessenger(this, REQUEST_CODE_SHARE_TO_MESSENGER, shareToMessengerParams);**/
}
我确定文件创建工作原因我已经测试过了。在测试中我从messenger收到以下错误“抱歉,Messenger无法处理该文件”。 我怎么解决?
答案 0 :(得分:0)
替换:
Uri.parse(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg")
使用:
Uri.fromFile(f)