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

后端 未结 11 1019
别跟我提以往
别跟我提以往 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:02

    Intent intent = new Intent(Intent.ACTION_SEND);
            String[] recipients = {"recipient@gmail.com"};//Add multiple recipients here
            intent.putExtra(Intent.EXTRA_EMAIL, recipients);
            intent.putExtra(Intent.EXTRA_SUBJECT, "Mail Subject"); //Add Mail Subject
            intent.putExtra(Intent.EXTRA_TEXT, "Enter your mail body here...");//Add mail body
            intent.putExtra(Intent.EXTRA_CC, "mailcc@gmail.com");//Add CC emailid's if any
            intent.putExtra(Intent.EXTRA_BCC, "mailbcc@gmail.com");//Add BCC email id if any
            intent.setType("text/html");
            intent.setPackage("com.google.android.gm");//Added Gmail Package to forcefully open Gmail App
            startActivity(Intent.createChooser(intent, "Send mail"));
    

提交回复
热议问题