Pages

Saturday, August 29, 2015

Making Phone Calls And Emails Android

Making Phone Calls And Emails Android



An Intent is an abstract description of an operation to be performed. It can be used with startActivity to launch an Activity or broadcastIntent to send it to any interested BroadcastReceiver components. Basically, an intent is a medium to start an activity.


Android has two types of Intents, Explicit & Implicit.

1) Explicit

This type of Intents are used in activities within an application. For instance, if you want to start another activity from your app, there comes explicit intent.
eg. startActivity(new Intent( " android.intent.action.myapp " ));

2) Implicit

This type of Intents are used to call third party application activities from your application . For instance, if you want to make a phone call from your app, there comes implicit intent.
eg. Intent intent = new intent (Intent.Action_Call);          //will make a call


Making Phone Calls In Android


Its pretty easy to make phone calls in android. We have to use Implicit intent. Take a look at this snippet :

Intent intent = new Intent ( Intent.Action_Call );
intent.setData(Uri.parse("tel:02223125678"));
startActivity(intent); 


The above code will make a call to the specified number.

Intent intent = new Intent ( Intent.Action_Call );  

Here, we make an object " intent " and pass a calling method to it.

intent.setData(Uri.parse("tel:02223125678"));

Here, we pass the number to the intent.

In my opinion, never use Intent.Action_Call. Instead, use Intent.Action_Dial. In many cases, it happens in mischief that we tap on the button and the call is generated. Instead, using dial, it will open the dial pad with the number in it. So, if the user need, he may press the call button or come back to the app.  



Making Emails In Android



Electronic mails have become a replacement to pen and paper. Thus, think if you could send emails from your app. But is that important ?? Yes, it might be. Consider, you have an app for your business. Then we can add a suggestion box to your app which by default will be an email. 

As shown earlier, we have to use Implicit intent. Take a look at this snippet :

Intent intent = new intent( Intent.Action_View );
intent.setType("plain/text");
intent.setClassName("com.google.android.gm","com.google.android.gm.ComposeActivityGmail");
intent.setData(Uri.parse(" example@example.com "));
intent.putExtra(Intent.Extra_Subject," Your Subject Goes Here ");
startActivity(intent);

The above code will start your gmail app with your email (ie. From) , receiver's email (i.e To : example@example.com) and the subject. Now, your user will type the message and hit send.

Done !! 


Thank You


No comments:

Post a Comment