【问题标题】:FileUriEXposedException in Sharing screenshot of a layout共享布局屏幕截图中的 FileUriEXposedException
【发布时间】:2019-02-07 18:05:27
【问题描述】:

嘿,我正在尝试分享布局的屏幕截图。它在所有小于奥利奥的版本中都运行良好,但是当我尝试在奥利奥上分享时,它给出了 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();
    }

【问题讨论】:

    标签: java android file android-studio uri


    【解决方案1】:

    自 oreo 以来,不再允许通过共享路径来共享文件的 AFAIK。我前段时间遇到过这个问题。

    我的解决方案是与内容提供者共享文件内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-30
      • 1970-01-01
      • 1970-01-01
      • 2021-11-18
      相关资源
      最近更新 更多