Dskato Dskato - 2 years ago 316
Android Question

android.content.ActivityNotFoundException: No Activity found to handle Intent

please help , when i run the app, the app launch a Fatal Error im learning
just i create a instat with a call but not run, (sorry for my english)
.......................................................................

my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.octa.appprueba3">

<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.APP_CONTACTS" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity"></activity>
</application>

</manifest>


my code:

public class SecondActivity extends AppCompatActivity {

private EditText editPhoneText;
private ImageButton imageCallButton;
private final int PHONE_CALL_CODE = 100;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);

editPhoneText = (EditText) findViewById(R.id.editTextPhone);
imageCallButton = (ImageButton) findViewById(R.id.imageCallButton1);

imageCallButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
implicito();
}
});
}

public void implicito(){

Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("Tel: 9999999" ));
startActivity(intent);

}
}

Answer Source

You may want to check whether your device can handle your intent by doing this:

PackageManager packageManager = getPackageManager();
if (intent.resolveActivity(packageManager) != null) {
    startActivity(intent);
} else {
     Log.d(TAG, "Cannot handle this intent");
}

What's more, if you are placing a call like so, there is NO need to declare the permission in your manifest:

<uses-permission android:name="android.permission.CALL_PHONE" />

Because you are not directly calling someone within your app. You are actually transferring the "duty" to other apps which can handle your intent to call. This doesn't need a permission.

To directly make a call within your app, the intent should be Intent.ACTION_CALL, which needs the permission you declared.

Hope this will help.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download