Here is main activity.
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText number;
Button makecall;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
number = findViewById(R.id.number);
makecall = findViewById(R.id.makecall);
call();
}
private void call() {
makecall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent;
intent = new Intent(Intent.ACTION_DIAL);
intent = intent.setData(Uri.parse("number:"+number.getText().toString()));
startActivity(intent);
}
});
}
}
I added this permission request to manifest file.
<uses-permission android:name="android.permission.CALL_PHONE"/>
Here is my XML file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.bimstajyer1.calisma10.MainActivity">
<EditText
android:id="@+id/number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Number"
android:inputType="number"
android:maxLength="11" />
<Button
android:id="@+id/makecall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Make a call" />
</LinearLayout>
I am this getting error when I press the call button to make call.
FATAL EXCEPTION: main
Process: com.example.bimstajyer1.calisma10, PID: 25198 android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.DIAL dat=number: }
Error line is : startActivity(intent);