我一直在努力解决这个问题。我有它。该应用程序正在将图片发送到任何其他应用程序。我尝试使用 WhatsApp、Gmail 等。但是,现在它无法正常工作。会是什么?包装问题?密钥库问题?现在,当我尝试使用 Gmail 时,附件会显示出来,但它看起来像一张带有名称的空图片。这意味着在智能手机上找不到文件。多谢你们。
private ShareActionProvider mShareActionProvider;
private void dragonFile(){
Bitmap dragonFront = BitmapFactory.decodeResource(getResources(),R.drawable.phoenix_art);
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
OutputStream outputStream = null;
File file = new File(extStorageDirectory, "phoenix_art.jpeg");
try{
outputStream = new FileOutputStream(file);
dragonFront.compress(Bitmap.CompressFormat.JPEG, 90, outputStream);
outputStream.flush();
outputStream.close();
} catch (Exception e){
e.printStackTrace();
}
private Intent getDefaultShareIntent(){
Intent shareIntent = new Intent();
shareIntent.setType("image/jpeg");
shareIntent.setAction(Intent.ACTION_SEND);
dragonFile();
File downloadedPic = new File(Environment.getExternalStorageDirectory().toString(), "phoenix_art.jpeg");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));
return shareIntent;
}
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.share_menu, menu);
MenuItem item = menu.findItem(R.id.menu_item_share);
mShareActionProvider = (ShareActionProvider) item.getActionProvider();
mShareActionProvider.setShareIntent(getDefaultShareIntent());
return super.onCreateOptionsMenu(menu);
}