The error appears when I click the TELEPHONE CALL button.
MainActivity class
package com.edu.chamada;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.content.Intent;
import android.net.Uri;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class MainActivity extends AppCompatActivity {
Button btnChamar;
Button btnTelefone;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnChamar = (Button) findViewById(R.id.btnChamar);
btnTelefone = (Button) findViewById(R.id.btnTelefone);
btnChamar.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse("http://www.google.com.br");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
finish();
}
});
btnTelefone.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse("34621026");
Intent it = new Intent(Intent.ACTION_CALL);
iniciarTelefone(it);
}
});
}
public void iniciarTelefone(Intent it){
startActivity(it);
finish();
}
//Criar um menu da aplicação
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main,menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id == R.id.acaoTelefonar){
Log.i("Saida do Menu", "Você escolheu: "+ id);
}
return super.onOptionsItemSelected(item);
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context="com.edu.chamada.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnChamar"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="37dp"
android:layout_marginTop="21dp"
android:text="@string/btnChamar"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnTelefone"
android:layout_marginTop="24dp"
android:layout_alignLeft="@+id/btnChamar"
android:layout_below="@+id/btnChamar"
android:text="@string/btnTelefone"/>
</RelativeLayout>
ERROR
05-31 14:28:39.017 2103-2103/com.mantovani.projetotelefone E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mantovani.projetotelefone, PID: 2103
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
at android.app.Activity.startActivityForResult(Activity.java:3424)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivityForResult(Activity.java:3385)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
at android.app.Activity.startActivity(Activity.java:3627)
at android.app.Activity.startActivity(Activity.java:3595)
at com.mantovani.projetotelefone.MainActivity.iniciarTelefone(MainActivity.java:54)
at com.mantovani.projetotelefone.MainActivity$2.onClick(MainActivity.java:49)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
[ 05-31 14:28:39.027 1567: 1688 D/ ]
HostConnection::get() New Host Connection established 0xb8f012a0, tid 1688