Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sir, I have created an application which connects to a specific website and calls a particular person etc., I have generated a signed ".apk" successfully without any errors and my application also runs on my android device but it fails to call a particular number. Kindly help me to solve this problem.

here is what I have done:

I have created a button for calling:

XML
<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="call me?"
        android:id="@+id/button4"
        android:layout_below="@+id/editText4"
        android:layout_alignRight="@+id/textView4"
        android:layout_alignEnd="@+id/textView4" />


Added a manifest file:

XML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.vis.vis" >
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />


Declared and defined the button to call:
Java
final Button call = (Button) findViewById(R.id.button4);
call.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent in=new Intent(Intent.ACTION_CALL,Uri.parse("1234567890"));
                try{
                    startActivity(in);
                }

                catch (android.content.ActivityNotFoundException ex){
                    Toast.makeText(getApplicationContext(),"Try again!",Toast.LENGTH_SHORT).show();
                }
            }
        });


but it goes for catch part pop-upping "Try again!"
Have I missed anything?
Sir, Kindly help me with this.
Posted

In your button onClick set this code :

Java
Intent in= new Intent(Intent.ACTION_CALL);
in.setData(Uri.parse("tel:0123456789"));
startActivity(in);
 
Share this answer
 
Comments
[no name] 29-Nov-15 7:06am    
Thank you Sir for your kind help.I have spotted out the error.
ridoy 29-Nov-15 7:29am    
welcome.
Change
Java
Intent in=new Intent(Intent.ACTION_CALL,Uri.parse("1234567890"));

to
Java
Intent in=new Intent(Intent.ACTION_CALL,Uri.parse("tel:1234567890"));


-KR
 
Share this answer
 
Comments
[no name] 29-Nov-15 7:06am    
Thank you Sir for your kind help.I have spotted out the error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900