Android 通过电子邮件发送的附件大小为0 KB

Android 通过电子邮件发送的附件大小为0 KB,android,android-intent,email-client,Android,Android Intent,Email Client,我正在开发一个应用程序,其中我必须通过电子邮件发送图像。我成功发送电子邮件,但发送的附件大小为0KB。我不明白问题出在哪里。下面是我的代码 import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widg

我正在开发一个应用程序,其中我必须通过电子邮件发送图像。我成功发送电子邮件,但发送的附件大小为0KB。我不明白问题出在哪里。下面是我的代码

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class EtestActivity extends Activity {
/** Called when the activity is first created. */
Button email;
Intent in;
private static final String TAG = "EmailLauncherActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    email = (Button)findViewById(R.id.email);
    email.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            try {
                in = new Intent(Intent.ACTION_SEND);
                in.setType("image/jpeg");
                in.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/android.jpg"));

                startActivity(Intent.createChooser(in, "Email..."));
            } catch (Exception e) {
                Log.e(TAG, "email sending failed", e);
            }//catch
        }//onClick
    });
}//onCreate
}//class

您的手机当时是否已安装到计算机上?SD卡在连接到您的计算机时可能无法访问,因此它可能没有实际连接图像。

您的手机当时是否已安装到您的计算机上?SD卡在连接到您的计算机时可能无法访问,因此它可能没有实际附加图像。

我还面临着通过更改MIME类型解决的相同问题


在.setType(“image/jpg”)中试试这个

我也面临同样的问题,通过更改MIME类型可以解决这个问题


在.setType(“image/jpg”)中试试这个

没有,我已经给我的模拟器提供了sd卡支持,我在其中保存了图像。我在手机上分别测试了同一个应用程序,并且在sd卡中保存了一张名为android.jpg的图像。但是,在这两种情况下,我都面临着同样的问题。不,我在保存图像的模拟器上提供了sd卡支持。我在手机上分别测试了同一个应用程序,并且在sd卡中保存了一张名为android.jpg的图像。但是,我在这两种情况下都面临着相同的问题。还有一个问题是,当我使用createchooser()时,它会显示所有能够发送文件的应用程序的列表,但我只需要电子邮件客户端的列表。您能告诉我如何获取该文件吗?请尝试使用Intent.ACTION\u SENDTO而不是Intent.ACTION\u SENDTO。我面临的另一个问题是,由于我使用了createchooser(),它显示了所有能够发送文件的应用程序的列表,但我只需要电子邮件客户端的列表。你能告诉我怎么做吗?试着用Intent.ACTION\u SENDTO代替Intent.ACTION\u SEND