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);
}
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.
ActivityNotFoundException on some Android devices
Operating Systems with this exception are 4.4.4 and 5.0.1
No. You happen to have received crash notices for those OS versions. There are ~2 billion Android devices, and this sort of problem can happen on any of them.
Any ideas for this exception
You are assuming that each and every one of those ~2 billion Android devices have one or more apps with an activity matching Intent.ACTION_MAIN
and Intent.CATEGORY_APP_MUSIC
. There is no requirement for any of those devices to have such an activity.
proposals to avoid it?
Option #1: Wrap your startActivity()
call in a try
/catch
block and catch the ActivityNotFoundException
, then tell the user that you cannot find a suitable app.
Option #2: Use PackageManager
and queryIntentActivities()
to see if there are any matches for the Intent
. If there are none, do not call startActivity()
, then tell the user that you cannot find a suitable app.
How to handle the ActivityNotFoundException?
Just simply add that activity in your manifest file..
like,
<activity android:name=".ActivityName"
android:label="@string/app_name">
</activity>
EDIT:
Now to catch the ActivityNOtFoundException
put your code in,
try {
// Your startActivity code wich throws exception
} catch (ActivityNotFoundException activityNotFound) {
// Now, You can catch the exception here and do what you want
}
Note: Be careful when you catch this ActivityNotFound Exception but you can't modified manifest file to run time, means once you encountered the exception and if you want to add that this activity tag at runtime then you can't.
ActivityNotFoundException on Android 7.1.1
The problem is that you force the system to open the intent, without checking if there's an application that can handle the intent. Probably you're trying to open the PDF on a device that has not an application for reading a PDF file. Try using this code:
PackageManager packageManager = getActivity().getPackageManager();
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent);
} else {
Log.d(TAG, "No Intent available to handle action");
}
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);
}
}
ActivityNotFoundException when opening a URL in browser on notification click
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(movieURL));
I am uncertain what movieURL
contains, but it is turning into link>https:
when you parse it. That is not a valid URL, and Android will not find an app to be able to handle ACTION_VIEW
for it.
Note that raising a Notification
from your app, where the Notification
launches a third-party app when clicked, is unusual. The typical point behind a Notification
is to allow the user to control aspects of your app's behavior. If your objective is to launch an activity from your own app, do not use an implicit Intent
(new Intent(Intent.ACTION_VIEW, ...)
). Instead, use an explicit Intent
(new Intent(this, YourAwesomeActivity.class)
). You can still use setAction()
or putExtra()
to attach information to tell your activity what to display.
ActivityNotFoundException Error while single click on View Holder
You are trying to go to EditText
instead of EditActivity
Replace
Intent intent = new Intent(MainActivity.this, EditText.class);
with
Intent intent = new Intent(MainActivity.this, EditActivity.class);
Related Topics
Android:Change Button Text and Background Color
Sqlite Query in Android to Count Rows
Multiple Apps Use Same Content Provider
Failed to Launch Emulator: Error: Emulator Didn't Connect Within 60 Seconds
Android Camera: Onactivityresult() Intent Is Null If It Had Extras
Android Fragmenttransaction Custom Animation (Unknown Animator Name: Translate)
Change Device Language via Adb
Updated Sdk Version, Getting Classnotfoundexception: Android.Support.V4.View.Viewpager
How Can Retrofit 2.0 Parse Nested JSON Object
Issues with Android Tabhost Example
Why Is Listview.Getcheckeditempositions() Not Returning Correct Values
How to Pass Values Between Activities on Android