postheadericon Android Phone Call Example


Definition: Create an application to call specific entered number by user in the EditText


Ex14.java


package bsr.exa;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;



public class E14 extends Activity {
/**  @author Bipin S Rupadiya , www.BipinRupadiya.com
     *
     *  14) Create an application to call specific entered number by user in the EditText
     *
     *  */
Button btnCall;
EditText txtNo;
   // @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
     
         btnCall=(Button)findViewById(R.id.btnCall);
         txtNo=(EditText)findViewById(R.id.txtNumber);
        btnCall.setOnClickListener(new OnClickListener() {

public void onClick(View arg0)
{

if(txtNo.getText().toString().equals(""))
{
Toast.makeText(E14.this, "Enter Number", Toast.LENGTH_LONG).show();
txtNo.requestFocus();
}
else
{
try
{
       Intent callIntent = new Intent(Intent.ACTION_CALL);
       callIntent.setData(Uri.parse("tel:"+txtNo.getText().toString()));
       startActivity(callIntent);
   }
catch (Exception e)
   {
Toast.makeText(E14.this,  " "+e.toString(), Toast.LENGTH_LONG).show();
   }
}


}
});
     
 }
    //@Override
    public void onDestroy()
{
super.onDestroy();

}
}

AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="bsr.exa"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".E14"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>




0 comments:

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.