snachmsm snachmsm - 18 days ago 4
Android Question

Unexpected Intent with action WEB_SEARCH

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)

Answer

I have to answer my own question for another future searchers, again...

@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();
    }
}