1.Create a Class Call_Utils
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
public class Call_Utils {
/**
* @param str_phno
* @param activity
* Function for calling a contact.
*/
public static void Call_contact(String str_phno,Activity activity){
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"
+ str_phno.trim()));
activity.startActivity(intent);
}
}
2.Use this in your MainActivity
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Call_Utils.Call_contact("09123456789", MainActivity.this);
}
}
3.Add permission in manifest file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.call_sample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<!-- Call Phone Permissions -->
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Now,you can use call function programmatically.
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
public class Call_Utils {
/**
* @param str_phno
* @param activity
* Function for calling a contact.
*/
public static void Call_contact(String str_phno,Activity activity){
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"
+ str_phno.trim()));
activity.startActivity(intent);
}
}
2.Use this in your MainActivity
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Call_Utils.Call_contact("09123456789", MainActivity.this);
}
}
3.Add permission in manifest file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.call_sample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<!-- Call Phone Permissions -->
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Now,you can use call function programmatically.
No comments:
Post a Comment