打开电子邮件意图并发送屏幕截图

时间:2018-03-18 21:05:56

标签: android email android-studio android-intent

我有一个功能,我想拍摄当前活动的屏幕截图,并允许我将其作为电子邮件发送。

        String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + ".jpg";

        // 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.JPEG, quality, outputStream);
        outputStream.flush();
        outputStream.close();
        File filelocation = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), mPath);
        Uri path = Uri.fromFile(filelocation);

        Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
        emailIntent.setData(Uri.parse("mailto:"));
        // set the type to 'email'
        emailIntent .setType("message/rfc822");
        String to[] = {"xxx@outlook.com"};
        emailIntent .putExtra(Intent.EXTRA_EMAIL, to);
        // the attachment
        emailIntent .putExtra(Intent.EXTRA_STREAM, path);
        // the mail subject
        emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Subject");
        startActivity(Intent.createChooser(emailIntent , "Send yourself your journey......"));

它似乎没有截取屏幕截图,当我打开电子邮件提示时,我收到以下消息。 "与此操作相关联的所有应用都已被禁用,阻止或未安装"

我使用三星s8作为我的测试设备只是因为这会产生影响并且我已经为我的应用程序授予了所有权限。

0 个答案:

没有答案