Java 如何使用android';你的意图是什么?

Java 如何使用android';你的意图是什么?,java,android,file,email,storage,Java,Android,File,Email,Storage,我正试图发送一封带有附件的电子邮件。文件在内部存储器中,因此这是我的代码: File filelocation = new File(getFilesDir().getAbsolutePath()+"/MyApp", "FileName"); Uri path = Uri.fromFile(filelocation); Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent

我正试图发送一封带有附件的电子邮件。文件在内部存储器中,因此这是我的代码:

File filelocation = new File(getFilesDir().getAbsolutePath()+"/MyApp", "FileName");
        Uri path = Uri.fromFile(filelocation);
        Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent .setType("vnd.android.cursor.dir/email");
        String to[] = {"mailmailmail@gmail.com"};
        emailIntent .putExtra(Intent.EXTRA_EMAIL, to);
        emailIntent .putExtra(Intent.EXTRA_STREAM, path);
        emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Subject");
        startActivity(Intent.createChooser(emailIntent , "Send email..."));
但我始终获得:
文件的权限被拒绝


如何解决此问题???

-确保已在清单中添加读取权限

使用权限android:name=“android.permission.READ\u EXTERNAL\u STORAGE”


-GMail 5.0只接受来自外部存储器的文件

您还可以使用这个库:编译'com.github.yesidlazaro:GmailBackground:1.1'

    String imagePath = data.getStringExtra(GOTOConstants.IntentExtras.IMAGE_PATH);

    BackgroundMail.newBuilder(ReportBugActivity.this)
            .withUsername("some_email@gmail.com")
            .withPassword("pages123")
            .withMailto("mail_to_email.bugs@gmail.com")
            .withSubject("Android Bug Report")
            .withAttachments(imagePath)
            .withBody("Android Bug Report")
            .withOnSuccessCallback(new BackgroundMail.OnSuccessCallback() {
                @Override
                public void onSuccess() {
                    Toast.makeText(getApplicationContext(), "Email Sent", Toast.LENGTH_LONG).show();

                    finish();
                    startActivity(getIntent());
                }
            })
            .withOnFailCallback(new BackgroundMail.OnFailCallback() {
                @Override
                public void onFail() {
                    Toast.makeText(getApplicationContext(), "Failed", Toast.LENGTH_LONG).show();
                }
            }).send();

我是这样解决的:我将要发送的文件复制到外部缓存目录中,然后发送它

File temporaryFile = null;
    try {
        temporaryFile = File.createTempFile(keyType.getKeyTypeString(), ".pem", context.getExternalCacheDir() );
        Utils.copy(new File(getFilesDir().getAbsolutePath()+"/"+ Utils.APP_OPERATOR_DIR, keyType.getKeyTypeString()+".pem"), temporaryFile);
    } catch (IOException e) {
        e.printStackTrace();
    }

File filelocation = new File(getFilesDir().getAbsolutePath()+"/MyApp", "FileName");
        Uri path = Uri.fromFile(filelocation);
        Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent .setType("vnd.android.cursor.dir/email");
        String to[] = {"mailmailmail@gmail.com"};
        emailIntent .putExtra(Intent.EXTRA_EMAIL, to);
        emailIntent .putExtra(Intent.EXTRA_STREAM, path);
        emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Subject");
        startActivity(Intent.createChooser(emailIntent , "Send email..."));

但是我的文件不在外部存储器中,而是在内部存储器中,您有读取内部存储器的权限吗?android.permission.READ\u INTERNAL\u storage我使用过这个库:编译'com.github.yesidlazaro:GmailBackground:1.1'。而且使用非常简单。GMail 5.0只接受来自外部存储的文件