In this
tutorial we will see how to make a call between two mobile. If our application
needs to enables a user to call a particular person saved in the Contacts
application, we can simplyuse an Intent object to bring up the Contacts
application, from which the user can select the person to call. In this
tutorial helps to avoid making large process. Now we will see how it works....
TRY IT OUT Calling Built-In Application Using Intents
1. Using Eclipse, create a new Android project and name it call.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff2a1703"
android:fadingEdge="horizontal"
android:gravity="top" >
<TextView
android:id="@+id/text"
android:text="Make Your Own Call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:typeface="serif"
android:textStyle="italic"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_marginTop="50dip"
android:textSize="20sp" >
</TextView>
<Button
android:id="@+id/login"
android:layout_width="400px"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp"
android:text="Fixed Call"
android:textSize="22sp"
android:textSize="22sp"
android:textStyle="bold"
android:typeface="serif" />
<Button
android:id="@+id/Button01"
android:layout_width="400px"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/login"
android:layout_centerVertical="true"
android:text="Dial Pad"
android:textSize="22sp"
android:textStyle="bold"
android:typeface="serif" />
</RelativeLayout>
3. Add the following statements to the CallActivity.java file.
package com.call;
package com.call;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.View.OnClickListener;
import android.os.Bundle;
import android.widget.Button;
public class CallActivity extends Activity
{
Button b1,b2;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b1=(Button) findViewById(R.id.login);
Button b2=(Button) findViewById(R.id.Button01);
b1.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
Intent in=new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+"9791012235"));
startActivity(in);
}
});
b2.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
Intent in1=new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+5556));
startActivity(in1);
}
});
}
}
4. Add the following statements to the androidmanifest.xml file.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.call"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".CallActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
</manifest>
5. Press F11 to debug the application on the Android Emulator.
6. Click the fixed call button to make a call directly to another mobile.
Categories:
Post a Comment