make a phone call click on a button

prasad.gai picture prasad.gai · Mar 23, 2011 · Viewed 137.6k times · Source

I'm trying to make a call when I press a button in android

((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);
  }
});

But when I run and click on the button it gives me the error

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?

Answer

Shaista Naaz picture Shaista Naaz · Mar 23, 2011

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.