您好evrybody我正在tryng,分享使者的形象,但我不知道爲什麼我的代碼doesen't的工作,我已經按照官方指導,https://developers.facebook.com/docs/messenger/android 有人可以告訴我爲什麼doese'nt工作?的Android,如何共享圖像文件與信使
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無法處理文件」。我如何解決?
呼叫'平齊()','getFD()同步()','和關閉後()'上'FileOutputStream'。 '寫()'。有一天,使用'FileProvider'而不是'Uri.fromFile()',因爲'fromFile()'在你的'targetSdkVersion'設置爲24或更高的時候不適用於Android 7.0+設備。請注意,並非所有應用都支持*'EXTRA_TEXT'和'EXTRA_STREAM'在同一個「ACTION_SEND」'Intent'上。並擺脫'setPackage()',所以你可以[分享用戶想要的](https://commonsware.com/blog/2011/06/28/share-where-the-user-wants.html)。 – CommonsWare
在write()之後,我在'FileOutputStream'上調用了'flush()','getFD()。sync()'和'close()',但仍然不起作用,我也刪除了'EXTRA_TEXT' – Rachid