Tuesday, March 14, 2017

Launching default SMS Activity and Phone Dialer Activity in Android

To launch default SMS app with text and number populated and launch phone call dialer pad with the number given, use the corresponding code snippet from below jist

//This just opens the default SMS app with To filled with contact of given phoneNumber and textBody filled into the text to be sent text box
public void openSMSApp (Context context, String phoneNumber, String text){
Uri smsUri = Uri.fromParts("sms", phoneNumber, null);
Intent intent = new Intent(Intent.ACTION_VIEW, smsUri);
intent.putExtra("sms_body", text);
context.startActivity(intent);
}
//This just opens the dialer with given phone number filled into the dialer
public void openPhoneCallApp (Context context, String phoneNumber){
Uri callUri = Uri.fromParts("tel", phoneNumber, null);
Intent intent = new Intent(Intent.ACTION_VIEW, callUri);
context.startActivity(intent);
}