Translate

Indonesian English French German Spain Italian Russian Portuguese Japanese Dutch Arabic Chinese Simplified

Intents:Use of intent to conduct a phone call

Wednesday, September 22, 2010


Project created named IntentsDial. In this application using the intent to make phone calls. Dialing of phone numbers can be performed using both ACTION_CALL ACTION_DIAL. ActionDial can be seen on the Source 1, while for the use of ACTION_CALL can be seen in the Source 2.
 1.    import Android.app.Activity;
2.    import Android.content.Intent;
3.    import Android.os.Bundle;
4.    import Android.net.Uri;

5.    public class IntentsDial extends Activity {
6.    /** Called when the activity is first created. */
7.    @Override
8.    public void onCreate(Bundle savedInstanceState) {
9.    super.onCreate(savedInstanceState);
10.    setContentView(R.layout.main);

11.    Intent DialIntent = new
12.    Intent(Intent.ACTION_DIAL,Uri.parse("tel:0298322550"));
13.    try{startActivity(DialIntent);}
14.    catch(Exception e){
15.    Log.d("Test",e.toString());
16.    }}
17.    }

Source 1. IntentsDial.java with ACTION_DIAL
Explanation:
• Line-11 and 12, used to make an object intent that has the attributes:
action: ACTION_DIAL
data: tel: 0298322550
so it will take action 0,298,322,550 telephone keystrokes.
• Line-13, used to start the activity of intent that have been made before. Use try and catch for error handling is received by the application. Log.d will display a message to the log on the eclipse (Figure 1).

 
Figure 1. LogCat
View the application in accordance Figure 2.
Figure 2. IntentsDial application when run

Calls can also be done immediately.
 1.    import Android.app.Activity;
2.    import Android.content.Intent;
3.    import Android.os.Bundle;
4.    import Android.util.Log;
5.    import Android.net.Uri;

6.    public class IntentsDial extends Activity {
7.    /** Called when the activity is first created. */
8.    @Override
9.    public void onCreate(Bundle savedInstanceState) {
10.    super.onCreate(savedInstanceState);
11.    setContentView(R.layout.main);

12.    Intent CallIntent = new
13.    Intent(Intent.ACTION_CALL,Uri.parse("tel:0298322550"));
14.    try{startActivity(CallIntent);}
15.    catch(Exception e)
16.    {
17.    Log.d("CallIntent",e.toString());
18.    }
19.    }
20.    }


Source 2. IntentsDial.java with ACTION_CALL

Explanation:
• On-line to 12 and 13, used to make an object intent that has the attributes:
action: ACTION_CALL
data: tel: 0298322550
so it will take action call 0298322550
• Line-14, used to start the activity of intent that have been made before. Use try and catch for error handling is received by the application.
Add the permissions on AndroidManifest.xml.

Applications will also do the calling. View the application in accordance Figure 3.

 
Figure 3. IntentsDial after modified when the application is run

0 comment:

Post a Comment

 
Theme by New wp themes | Bloggerized by Dhampire