4

我开发了一个发送电子邮件的应用程序。单击电子邮件按钮时,它应该要求用户选择安装在手机中的电子邮件客户端之一。但是,在我的情况下,它还显示了不需要的蓝牙选项。我搜索了很多,但找不到任何解决方案。下面我发布我的代码。

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/jpg");
                in.setType("plain/text");
                in.setType("application/octet-stream");
                in.putExtra(Intent.EXTRA_EMAIL, new String[]{"pranav_kotauniv@yahoo.co.in","friendlynitish@gmail.com"});
                in.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/android.jpg"));  
                startActivity(Intent.createChooser(in, "mailto:"));
            } catch (Exception e) {
                Log.e(TAG, "email sending failed", e);
            }//catch
        }//onClick
    });
}//onCreate

}//班级

4

3 回答 3

2

尝试使用 ACTION_SENDTO 而不是 ACTION_SEND。这可能会解决您的问题。
这是API。
您始终可以使用PackageManagerqueryIntentActivities()展示您自己的自定义对话框。

于 2012-05-02T10:06:22.723 回答
1

发送电子邮件的代码。使用 PackageManager(http://developer.android.com/reference/android/content/pm/PackageManager.html),我们可以避免得到不同的选择。

private void sendEpost(String type) {
boolean found = false;
Intent in = new Intent(android.content.Intent.ACTION_SEND);
in.setType("image/jpeg");
in.setType("application/octet-stream");
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(in, 0);
if (!resInfo.isEmpty()){
    for (ResolveInfo info : resInfo) {
        if (info.activityInfo.packageName.toLowerCase().contains(type) || 
                info.activityInfo.name.toLowerCase().contains(type) ) {
            in.putExtra(Intent.EXTRA_EMAIL, new String[]{});
            in.putExtra(Intent.EXTRA_SUBJECT,  "subject");
            in.putExtra(Intent.EXTRA_TEXT,     "your text");
            in.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(Environment.getExternalStorageDirectory()
                    .getAbsolutePath().toString()+"/diplomat/"+adapter.readName(touches))));
            in.setPackage(info.activityInfo.packageName);
            found = true;
            break;
        }
    }
    if (!found)
        return;
    startActivity(Intent.createChooser(in, "Select"));
}
}//sendEpost
于 2012-06-21T03:38:01.527 回答
0

你有 2 个选项来解决这个问题,

首先是,改变你的意图类型setType("message/rfc822");引用这个

其次是,更改您的 ACTION 类型Intent.ACTION_SENDTOReffer this

于 2012-05-02T10:17:11.237 回答