Problem description
This exception occurs when the corresponding activity is not found.
Solution
This exception occurs when the corresponding activity is not found. It is usually because the AndroidManifest.xml file does not contain the required activity path or the app does not exist in the device. We recommend that you check the activity path in the Android manifest file and catch the exception where the activity is enabled.
Sample code
android.content.ActivityNotFoundException: Unable to find explicit activity class {*}; have you declared this activity in your AndroidManifest.xml?Solution 1: Confirm that the required activity path is correct in the AndroidManifest.xml file
<activity
android:name="com.your.package.name.YourActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>Solution 2: Catch the exception
public static void startDialer(Context context, String phoneNumber) {
try {
Intent dial = new Intent();
dial.setAction(Intent.ACTION_DIAL);
dial.setData(Uri.parse("tel:" + phoneNumber));
context.startActivity(dial);
} catch (ActivityNotFoundException ex) {
Log.e(TAG, "Error starting phone dialer intent.", ex);
Toast.makeText(context, "Sorry, we couldn't find any app to place a phone call!",
Toast.LENGTH_SHORT).show();
}
}References
https://developer.android.com/reference/android/content/ActivityNotFoundException.html
http://stackoverflow.com/questions/15825081/error-default-activity-not-found
https://developer.android.com/guide/topics/manifest/manifest-intro.html (Android manifest file)
https://developer.android.com/guide/topics/manifest/activity-element.html (Activity syntax)