Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过电子邮件发送屏幕截图Android 8.0_Android_Android Intent_Android 8.0 Oreo - Fatal编程技术网

通过电子邮件发送屏幕截图Android 8.0

通过电子邮件发送屏幕截图Android 8.0,android,android-intent,android-8.0-oreo,Android,Android Intent,Android 8.0 Oreo,我以前也问过类似的问题,但我自己解决了。但我现在有了一个新问题,我的设备更新到了安卓8.0,而现在电子邮件意图无法工作。如果可能的话,我不想降级我的设备 private void sendScreen() { Date now = new Date(); android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now); try { // image naming and path to

我以前也问过类似的问题,但我自己解决了。但我现在有了一个新问题,我的设备更新到了安卓8.0,而现在电子邮件意图无法工作。如果可能的话,我不想降级我的设备

private void sendScreen() {
    Date now = new Date();
    android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);

    try {
        // image naming and path  to include sd card  appending name you choose for file
        String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + ".png";

        // create bitmap screen capture
        View v1 = getWindow().getDecorView().getRootView();
        v1.setDrawingCacheEnabled(true);
        Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
        v1.setDrawingCacheEnabled(false);

        File imageFile = new File(mPath);

        FileOutputStream outputStream = new FileOutputStream(imageFile);
        int quality = 100;
        bitmap.compress(Bitmap.CompressFormat.PNG, quality, outputStream);
        outputStream.flush();
        outputStream.close();

        File filelocation = new File(MediaStore.Images.Media.DATA  + mPath);
        Uri myUri = Uri.parse("file://" + filelocation);
        final Intent emailIntent = new Intent(Intent.ACTION_SEND);
        // set the type to 'email'
        emailIntent .setType("vnd.android.cursor.dir/email");
        String to[] = {"Enter your email address"};
        emailIntent .putExtra(Intent.EXTRA_EMAIL, to);
        // the attachment
        emailIntent.putExtra(Intent.EXTRA_STREAM, myUri);
        // the mail subject
        emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Journey : " + now );
        startActivity(Intent.createChooser(emailIntent , "Select your preferred email app.."));


    } catch (Throwable e) {
        // Several error may come out with file handling or DOM
        e.printStackTrace();
    }
}
这是我在安卓7.0上完美运行的代码。代码会截取一个屏幕截图,加上时间戳,将其保存到本地存储,然后将其附加到用户选择的电子邮件应用程序。有人有办法吗?谢谢

这是我在安卓7.0上完美运行的代码

它本应与
FileUrieExposedException
一起崩溃

现在,电子邮件意图不起作用


你没有解释“不工作”是什么意思。我猜你是因为一个
FileUriExposedException
而崩溃的。默认情况下,无论是通过
Uri.fromFile()
还是您的
Uri.parse(“file://“+…)
方法,
文件
Uri
,在Android 7.0+上都不可用。和
getUriForFile()

不,我不会崩溃,它不会截图或打开电子邮件。好的,我试试