prasad.gai prasad.gai - 6 months ago 46
Android Question

make a phone call click on a button

i am a new programer in android application

i have created a button in my application, when i clicked on a button then i would like to make a call.i have written code as follows

((Button)findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String phno="10digits";

Intent i=new Intent(Intent.ACTION_DIAL,Uri.parse(phno));
startActivity(i);
}
});


when i run this application it is displaying button,when i clicked on button then i am getting force close error.the error showing in log cat as follows

03-23 15:04:16.166: ERROR/AndroidRuntime(1021): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=9392438004 }


how can i resolve this problem...

please help me

thanks in advance

Answer

Have you given the permission in the manifest file

 <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>   

and inside your activity

  Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse("tel:123456789"));
    startActivity(callIntent);

Let me know if you find any issue.

Comments