Android - 尝试发送电子邮件时收到错误"没有应用程序可以执行此操作"?

Var*_*oid 10 email android feedback dialog

我正在制作一个应用程序,我将向我的客户提供反馈功能.为了实现这一点,我创建了一个小对话框,用户可以在其中输入反馈并将其发送到我的邮件ID.我尝试了一些我在互联网上找到的代码片段,但每当我尝试从模拟器或实际设备发送电子邮件时,我都会收到错误消息"没有应用程序可以执行此操作".

这是我的代码: -

public void emailDialog()
{
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
    alertDialog.setTitle("Feedback");
    alertDialog.setMessage("Please tell us that what you feel about our product. If you are facing any problem or found any bug then please report to us. Your review is important to us. Thanks!!");
    final EditText input = new EditText(this);
    input.setLines(8);
    alertDialog.setView(input);
    alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            String value = input.getText().toString();
            String address = "varundroid@gmail.com";
            String subject = "FeedBack";
            final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, address);
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, value);
            CompleteTaskManager.this.startActivity(Intent.createChooser(emailIntent, "Send Email.."));
        }
    });
    alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int whichButton) {
        // Canceled.
      }
    });
alertDialog.show();
}
Run Code Online (Sandbox Code Playgroud)

请帮忙.

Jos*_*hin 18

我认为你需要设置intent对象的类型.你能试试以下吗?

emailIntent.setType("message/rfc822");
Run Code Online (Sandbox Code Playgroud)

要么

emailIntent.setType("text/plain");
Run Code Online (Sandbox Code Playgroud)

  • 没问题......我认为地址变量必须是一个String数组.像String address = {"varundroid@gmail.com"}之类的东西; (2认同)