Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Java (Android Studio) Tutorial – QuickMail –
package codingwithsara.com.quickmail;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void sendMessage(View view) {
// Get Checked RadioButton Ids
int toId = ((RadioGroup)findViewById(R.id.radioGroup1)).getCheckedRadioButtonId();
int msgId = ((RadioGroup)findViewById(R.id.radioGroup2)).getCheckedRadioButtonId();
// Get Text by Id
String toName = ((RadioButton)findViewById(toId)).getText().toString();
String message = ((RadioButton)findViewById(msgId)).getText().toString();
// Check name & message.
// Log.v("TO:", toName);
// Log.v("Message:", message);
// Set email address.
String email = "";
switch (toName) {
case "Mom":
email = "mom@sample.com";
break;
case "Boss":
email = "boss@sample.com";
break;
case "Friend":
email = "friend@sample.com";
break;
}
// Check email.
//Log.v("Email:", email);
Uri uri = Uri.parse("mailto:" + email);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra(Intent.EXTRA_SUBJECT, "Sent from QuickMail App.");
intent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(intent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment