android.content.ActivityNotFoundException:
Maybe you need to check that you added the new activity to the manifest.xml file
Example:
<activity
android:name=".className"
android:label="@string/app_name" >
</activity>
android.content.ActivityNotFoundException: Unable to find explicit activity class Android Studio Kotlin Error
Replace:
R.layout.registration::class.java
with:
Registration::class.java
You are attempting to use a resource ID as an Activity
class, and that will not work.
How to fix android.content.ActivityNotFoundException android-studio 2.3.3
The result when you scan a barcode is often not a valid URL. It is often just a string with several digits. It has no schema or protocol, so it is (very possibly) not defined "what type of resource locator it is". Android's ACTION_VIEW intent is mostly use this information to decide "start which app/activity to open this URL". With a lack of the important information, Android has no idea to open it.
You may specify some cases for handling the result. For example, if the result begins with "http://" or "https://", directly use your code to handle, but if it is just a string of numbers, display it directly, or append it after some string before it is used for Uri.parse
, for example "https://google.com/search?q=", to search this barcode's value as you may wanted, or other things you want to do with that 13 digit result.
For example, (the code below written in mobile hasn't been tested, just show the idea):
@Override
public void onClick(DialogInterface dialog, int which) {
Intent browserIntent;
if (myResult.startsWith("http://") || myResult.startsWith("https://"))
browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myResult));
else
browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://google.com/search?q=" + myResult));
startActivity(browserIntent);
}
Fatal Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent
I create a method which based on @andreban's answer. I believe it will open url %99.99 times.
public static void openURL(Context mContext, Uri uri) {
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setShowTitle(true);
CustomTabsIntent customTabsIntent = builder.build();
Intent browserIntent = new Intent()
.setAction(Intent.ACTION_VIEW)
.addCategory(Intent.CATEGORY_BROWSABLE)
.setType("text/plain")
.setData(Uri.fromParts("http", "", null));
List<ResolveInfo> possibleBrowsers;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
possibleBrowsers = mContext.getPackageManager().queryIntentActivities(browserIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (possibleBrowsers.size() == 0) {
possibleBrowsers = mContext.getPackageManager().queryIntentActivities(browserIntent, PackageManager.MATCH_ALL);
}
} else {
possibleBrowsers = mContext.getPackageManager().queryIntentActivities(browserIntent, PackageManager.MATCH_DEFAULT_ONLY);
}
if (possibleBrowsers.size() > 0) {
customTabsIntent.intent.setPackage(possibleBrowsers.get(0).activityInfo.packageName);
customTabsIntent.launchUrl(mContext, uri);
} else {
Intent browserIntent2 = new Intent(Intent.ACTION_VIEW, uri);
mContext.startActivity(browserIntent2);
}
}
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=zhanysch@gmail.com }
Your intent for opening Gmail is wrong. I recommend looking into "Send email intent" in Android.
But for the simple case, change this:
val client = Intent(Intent.ACTION_VIEW , Uri.parse("zhanysch@gmail.com"))
into this:
val client = Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:zhanysch@gmail.com"))
For a better, more generic solution, I recommend checking the official docs.
Related Topics
Context.Startforegroundservice() Did Not Then Call Service.Startforeground()
Difference Between Getdefaultsharedpreferences and Getsharedpreferences
Android Drawing Separator/Divider Line in Layout
Android Spinner: Get the Selected Item Change Event
How to Make Ellipsize="Marquee" Always Scroll
The Setmobiledataenabled Method Is No Longer Callable as of Android L and Later
How to Customize Snackbar's Layout
Set Transparent Background of an Imageview on Android
Android Pick Images from Gallery
What Is Activity.Finish() Method Doing Exactly
Android Starting Service At Boot Time , How to Restart Service Class After Device Reboot
Android Material and Appcompat Manifest Merger Failed
How to Set Navigation Drawer to Be Opened from Right to Left
Using Intent in an Android Application to Show Another Activity