How to open the default mail inbox from android code?

前端 未结 9 1643
执念已碎
执念已碎 2021-02-19 00:43

I\'m trying to link a button to the mail app. Not to send mail, but just to open the inbox.

Should I do this with Intent intent = new Intent(...)?

相关标签:
9条回答
  • 2021-02-19 01:05

    Any suggestions to avoid the crash if the default mail in the device is not configured?

    Yes, it's possible to open the Android default email inbox.
    Use this code:

    Intent intent = getPackageManager().getLaunchIntentForPackage("com.android.email");
    startActivity(intent);
    


    This code works, you have to configure your Android device default mail first. If you already configured your mail it works fine. Otherwise, it force closes with a NullPointerException.

    0 讨论(0)
  • 2021-02-19 01:07

    You can simply use below code when for no attachment:

    Intent i = new Intent(Intent.ACTION_SENDTO);
    i.setData(Uri.parse("mailto:support@mailname.com")); 
    i.putExtra(Intent.EXTRA_SUBJECT, "Feedback/Support");
    startActivity(Intent.createChooser(emailIntent, "Send feedback"));
    

    For details I recommend to visit: https://developer.android.com/guide/components/intents-common.html#Email

    0 讨论(0)
  • 2021-02-19 01:07

    You can open Android default e-mail client using this:

    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.setType("text/plain");
    emailIntent.setClassName("com.android.email", "com.android.email.activity.Welcome");
    emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(emailIntent);
    
    0 讨论(0)
提交回复
热议问题