For those using AppCompact...Try this
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.net.Uri;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button startBtn = (Button) findViewById(R.id.db);
startBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
makeCall();
}
});
}
protected void makeCall() {
EditText num = (EditText)findViewById(R.id.Dail);
String phone = num.getText().toString();
String d = "tel:" + phone ;
Log.i("Make call", "");
Intent phoneIntent = new Intent(Intent.ACTION_CALL);
phoneIntent.setData(Uri.parse(d));
try {
startActivity(phoneIntent);
finish();
Log.i("Finished making a call", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "Call faild, please try again later.", Toast.LENGTH_SHORT).show();
}
}
}
Then add this to your manifest,,,
<uses-permission android:name="android.permission.CALL_PHONE" />