How to open Gmail Compose when a button is clicked in Android App?

后端 未结 11 1018
别跟我提以往
别跟我提以往 2020-12-01 06:25

I am trying to open up Gmail Compose screen when a button is clicked in my Android App. Do I need some API key for this from Google? or what do I need to do in my button onC

11条回答
  •  鱼传尺愫
    2020-12-01 07:01

    You just place below code inside your click event. Will open directly gmail as compose mode, Output screenshot attached below.

    Happy coding :-)

    code :

    Intent intent=new Intent(Intent.ACTION_SEND);
    String[] recipients={"mailto@gmail.com"};
    intent.putExtra(Intent.EXTRA_EMAIL, recipients);
    intent.putExtra(Intent.EXTRA_SUBJECT,"Subject text here...");
    intent.putExtra(Intent.EXTRA_TEXT,"Body of the content here...");
    intent.putExtra(Intent.EXTRA_CC,"mailcc@gmail.com");
    intent.setType("text/html");
    intent.setPackage("com.google.android.gm");
    startActivity(Intent.createChooser(intent, "Send mail"));
    

    Output :

提交回复
热议问题