Reputation: 19273
I have pretty large app to inspect with a lot of activities. One of most popular exceptions is
No Activity found to handle Intent { act=android.intent.action.WEB_SEARCH (has extras) }
What the heck? I don't see in code any "WEB_SEARCH" anywhere, I can't reproduce it, I don't even know where to look for cause (in which Activity
). Below stack of Exception
, without any class from my package... How to track and fix this?
Fatal Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.WEB_SEARCH (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1659)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1434)
at android.app.Activity.startActivityForResult(Activity.java:3432)
at android.app.Activity.startActivityForResult(Activity.java:3393)
at android.support.v4.app.FragmentActivity.startActivityForResult(Unknown Source)
at android.app.Activity.startActivity(Activity.java:3628)
at android.app.Activity.startActivity(Activity.java:3596)
at android.webkit.SelectActionModeCallbackSec.onActionItemClicked(SelectActionModeCallbackSec.java:390)
at com.android.internal.policy.impl.PhoneWindow$DecorView$ActionModeCallbackWrapper.onActionItemClicked(PhoneWindow.java:3264)
at android.support.v7.view.SupportActionModeWrapper$CallbackWrapper.onActionItemClicked(Unknown Source)
at android.support.v7.app.AppCompatDelegateImplV7$ActionModeCallbackWrapperV7.onActionItemClicked(Unknown Source)
at android.support.v7.app.AppCompatDelegateImplV7$ActionModeCallbackWrapperV7.onActionItemClicked(Unknown Source)
at android.support.v7.view.StandaloneActionMode.onMenuItemSelected(Unknown Source)
at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(Unknown Source)
at android.support.v7.view.menu.MenuItemImpl.invoke(Unknown Source)
at android.support.v7.view.menu.MenuBuilder.performItemAction(Unknown Source)
at android.support.v7.view.menu.MenuBuilder.performItemAction(Unknown Source)
at android.support.v7.view.menu.MenuPopupHelper.onItemClick(Unknown Source)
at android.widget.AdapterView.performItemClick(AdapterView.java:301)
at android.widget.AbsListView.performItemClick(AbsListView.java:1490)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3275)
at android.widget.AbsListView$1.run(AbsListView.java:4518)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5283)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(NativeStart.java)
Upvotes: 2
Views: 2401
Reputation: 19273
I have to answer my own question for another future searchers. For use in Activity
with WebView
, or for safety in some Base
/MainActivity
abstract layer:
@Override
public void startActivityForResult(Intent i, int reqCode, Bundle b){
boolean activityExists = i.resolveActivityInfo(getPackageManager(), 0) != null;
if(activityExists)
super.startActivityForResult(i, reqCode, b);
else{
if(Intent.ACTION_WEB_SEARCH.equals(i.getAction()) && i.getExtras()!=null){
String query = i.getExtras().getString(SearchManager.QUERY, null);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.pl/search?q="+query));
boolean browserExists = i.resolveActivityInfo(getPackageManager(), 0) != null;
if(browserExists && query!=null){
startActivity(browserIntent);
return;
}
}
Toast.makeText(this, R.string.error_no_app_for_intent, Toast.LENGTH_LONG).show();
}
}
Reason of this behaviour is (probably) custom system UI/modded Android made by hardware producer, which is adding some features related with searching. Not reproducable on "clean" Android device
Upvotes: 5
Reputation: 56
Met the same issue recently, did some dig, i think snachmsm's answer is good, and i wanna make some analysis for other searchers.
Obviously no code written by me is starting an Intent with WEB_SEARCH, and according to the crash log, the intent is invoked by android.webkit.SelectActionModeCallbackSec.onActionItemClicked, so the fact is that if you use a webview, when the user long click and select some text , in some phones or themes or ROMs it will show an ActionMenu with "find" and "web search" or only one of them, depends on the various implementation. And when the user click "web search" it will start an intent with WEB_SEARCH.
Then the solution is simple, in the Activities that use a webview, override startActivityForResult to handle the certain intent. Why don't he override startActivity either? Because startActivity invoke startActivityForResult eventually.
Upvotes: 2