蓝牙选项即将进入选择列表

时间:2012-05-02 09:43:35

标签: android email android-intent

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

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

} //类

3 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分: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

答案 2 :(得分:0)

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

首先是,更改您的意图类型setType("message/rfc822"); Reffer this

其次是,更改您的行动类型Intent.ACTION_SENDTO Reffer this

相关问题