嘿,我正在尝试共享布局的屏幕截图。它在所有小于Oreo的版本中都很好用,但是当我尝试在Oreo上共享时,它给出FileUriExposedException。请如果有人知道此问题,请尽快解决。
这是我的代码
public Bitmap takeScreenshot() {
View rootView = (FrameLayout)findViewById(R.id.frame_layout).getRootView();
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
}
public void saveBitmap(Bitmap bitmap) {
imagepath1 = new File(Environment.getExternalStorageDirectory() + "/screenshot.png");
FileOutputStream fos;
try {
fos = new FileOutputStream(imagepath1);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
}
private void shareIt() {
try{
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
Uri uri = Uri.fromFile(imagepath1);
sharingIntent.setType("image/*");
String share_text = "*Create, Share, Download* Valentine Frames and spread love on this \nValentine\uD83D\uDE18\uD83D\uDE18 for free...." +
"\n*Download Now:-* https://play.google.com/store/apps/details?id=technoapps4.valentineframes2019";
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, share_text);
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
sharingIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(sharingIntent, "Share via"));}
catch ( Exception e)
{
Toast.makeText(this, ""+e, Toast.LENGTH_SHORT).show();
}
答案 0 :(得分:0)
自oreo开始,不再允许通过AFAIK共享文件路径来共享文件。我前段时间遇到了这个问题。
我的解决方案是与内容提供商共享文件内容。