电子邮件意图createChooser无法从DialogFragment中打开

时间:2015-08-27 05:10:29

标签: android email android-intent android-dialogfragment

我正在尝试直接通过DialogFragment上的按钮发送文件,但意图不会打开并被跳过。有什么想法吗?

此代码位于onCreateView

DialogFragment方法内
createWithEmail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //create file than move right into email
                fileName = editFileName.getText().toString();

                //create file
                createFile();

                //set up email
                Intent i = new Intent(Intent.ACTION_SEND);
                File file = new File(getActivity().getExternalCacheDir(), fileName);
                i.setType("image/png");
                i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
                i.putExtra(Intent.EXTRA_TEXT, "From:" + user.getName() + "\n" + "\n" + "Company Name:" + user.getCompany() + "\n" + "\n" + "Date of meeting to present:");
                try {
                    getActivity().startActivity(Intent.createChooser(i, "Send mail..."));
                } catch (android.content.ActivityNotFoundException ex) {
                    Toast.makeText(getActivity(), "There are no email clients installed.", Toast.LENGTH_SHORT).show();
                }

                //dismiss
                getDialog().dismiss();
                realm.close();
                startActivity(new Intent(getActivity(), OldLocation.class));
            }
        });

0 个答案:

没有答案