Make A Call From App

Put your problem here if it does not fit any of the other categories.

Make A Call From App

Postby grimx » Wed Dec 30, 2009 10:14 pm

I know you can use Intent.ACTION_DIAL to bring up the dialer with the supplied phone number.
But how do you make the actual call from an app, i know theres and Intent.ACTION_CALL.

here my code of a simple app enter the phone number and press the button to place the call

Code: Select all
package com.grimx.MakeCall;

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

public class MakeCall extends Activity implements View.OnClickListener{
    EditText editText;
    Button callBtn;
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        editText = (EditText)findViewById(R.id.editText);
        callBtn = (Button)findViewById(R.id.callBtn);
        callBtn.setOnClickListener(this);
    }

   @Override
   public void onClick(View v) {
      if(v.getId() == R.id.callBtn) {
         String phn_number = editText.getText().toString();
         if(!phn_number.equals("")) {
            //Intent dial_intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phn_number));
            //startActivity(dial_intent);
                               Intent call_intent = new Intent(Intent.ACTION_CALL); // not sure how to implement this
                               startActivity(call_intent);
         }
                  
      }
   }
   
   
}


and the layout for my app
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:orientation="vertical"
  4.    android:layout_width="fill_parent"
  5.    android:layout_height="fill_parent"
  6.    >
  7. <EditText
  8.         android:id="@+id/editText"
  9.         android:phoneNumber="true"
  10.    android:layout_width="fill_parent"
  11.    android:layout_height="wrap_content"
  12.    />
  13. <Button
  14.         android:id="@+id/callBtn"
  15.         android:layout_width="fill_parent"
  16.         android:layout_height="wrap_content"
  17.         android:text="Call"
  18.         />
  19. </LinearLayout>
  20.  
  21.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
Last edited by grimx on Wed Dec 30, 2009 10:53 pm, edited 1 time in total.
grimx
Junior Developer
Junior Developer
 
Posts: 20
Joined: Sat Dec 05, 2009 12:47 am

Top

Postby grimx » Wed Dec 30, 2009 10:52 pm

Problem solved
needed:
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.CALL_PRIVILEGED" />
grimx
Junior Developer
Junior Developer
 
Posts: 20
Joined: Sat Dec 05, 2009 12:47 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 23 guests