Search This Blog

Saturday, 28 April 2012

Utility Function Call, Email, Send SMS in android Using Intent

Generally while we making an android application then sometimes we need small piece of code like how to call a number on button click, how to send an email, how to send a sms. But problem is that it does not available at one place. So i am giving all possible Utility code here

1) How to call a number in android application

 Intent callIntent = new Intent(Intent.ACTION_CALL);  
 callIntent.setData(Uri.parse("tel:123456789"));  
 startActivity(callIntent);  


2) How to send an email in android application

 Intent(android.content.Intent.ACTION_SENDTO);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "testing email send.");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml("<b>this is html text in email body.</b>"));
startActivity(Intent.createChooser(emailIntent, "Email to Friend")); 



3) How to send SMS in android application

 SmsManager sm = SmsManager.getDefault();
String number = "6508570720";
sm.sendTextMessage(number, null, "Test SMS Message", null, null);


Note : Never forget to mention for sending SMS <uses-permission android:name="android.permission.SEND_SMS"></uses-permission>

Now enjoy these Utility in your application and feel free to support me by commenting and giving feedback

2 comments:

  1. Hi !
    have you tried sending sms using SMSManager to a bada or symbian phone, as my message gets trimmed, on android it works great, do you have any idea ?
    thanks in advance.

    ReplyDelete
    Replies
    1. I think i did not get you properly. Did your message trim when you send from android device to non android device?

      Delete

Feedback always help in improvement. If you have any query suggestion feel free to comment and Keep visiting my blog to encourage me to blogging

Android News and source code