Making phone Calls from your app
How to allow your app to make phone calls.
Your app can have access to phone calls. I will explain here how to do it. In order to test the code you can create an Eclipse project with an activity : My Activity for example. Insert a button in your main layout and then add this code to the onCreate() method of your Activity:
private String phoneNumber= "921234221"; Button button1 = (Button) this.findViewById(R.id.button1); button1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { try { Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:" + phoneNumber)); getContext().startActivity(callIntent); } catch (ActivityNotFoundException e) { Log.e("Your app", "call failed", e); } catch (SecurityException e2) { Log.e("Your app", "permission denied", e2); } } }) ;
In the android manifest you need to add the following line
<uses-permission android:name="android.permission.CALL_PHONE"/>
You don’t need to put an area code.
That’s it now your app can make phone calls. You can try this with the emulator.
Reply