javaandroidandroid-intentgoogle-now

Google Now intercepts `Intent.ACTION_VIEW` (Strange)


My problem is a bit weird, but I'll try to be specific. This is my code.

if(l.contains("search yahoo")||l.contains("yahoo search")&& !l.contains("search yahoo search"))
                    {
                        String query = l;
                        query = query.replace("search", "");
                        query = query.replace("yahoo", "");
                        String url = "http://search.yahoo.com/search?p=" + query;
                        Intent i = new Intent(Intent.ACTION_VIEW);
                        i.setData(Uri.parse(url));
                        startActivity(i);
                    }
                    if(l.contains("search bing")||l.contains("bing search")&& !l.contains("search bing search"))
                    {
                        String query = l;
                        query = query.replace("search", "");
                        query = query.replace("bing", "");
                        String url = "http://www.bing.com/search?q=" + query + "&go=Submit&qs=ds&form=QBLH";
                        Intent i = new Intent(Intent.ACTION_VIEW);
                        i.setData(Uri.parse(url));
                        startActivity(i);
                    }
                    else {
                        String v2txt = txt2SpeechWords.get(0);

                        v2txt = v2txt.replace("search", "");

                        txt2Speech.speak("searching " + v2txt, TextToSpeech.QUEUE_FLUSH, null);

                        Intent search = new Intent(Intent.ACTION_WEB_SEARCH);
                        search.putExtra(SearchManager.QUERY, v2txt);
                        startActivity(search);
                    } 

In the part where my program decides whether it should search Yahoo! or Bing for Bing it works perfectly. But for Yahoo! It opens in the web browser but when I hit the back button on my device it opens Google Now with the query except for the words Yahoo & Search as I have replaced them in the code.

Why does this happen? I am pretty sure the problem occurs after it has decided which search engine to use as in Google Now it removes the word Yahoo!

Why is Intent.ACTION_VIEW Intercepted by Google Now for the Yahoo! Part while this does not occur in the Bing part. It is pretty ironic since I pretty much copied the Yahoo! Code into notepad, replaced Yahoo as Bing & Pasted it in Android Studio.


Solution

  • I made the most dumbest mistake. In the yahoo part it is if and in bing it is if as well. Bing's if statement must be made else if. Also my question has a mistake. In google now it does not replace Yahoo! therefore the if statement is wrong. I just noticed. Sorry for that.

    Correct Code:

    if(l.contains("search yahoo")||l.contains("yahoo search")&& !l.contains("search yahoo search"))
                    {
                        String query = l;
                        query = query.replace("search", "");
                        query = query.replace("yahoo", "");
                        String url = "http://search.yahoo.com/search?p=" + query;
                        Intent i = new Intent(Intent.ACTION_VIEW);
                        i.setData(Uri.parse(url));
                        startActivity(i);
                    }
                    else if(l.contains("search bing")||l.contains("bing search")&& !l.contains("search bing search"))
                    {
                        String query = l;
                        query = query.replace("search", "");
                        query = query.replace("bing", "");
                        String url = "http://www.bing.com/search?q=" + query + "&go=Submit&qs=ds&form=QBLH";
                        Intent i = new Intent(Intent.ACTION_VIEW);
                        i.setData(Uri.parse(url));
                        startActivity(i);
                    }
                    else {
                        String v2txt = txt2SpeechWords.get(0);
    
                        v2txt = v2txt.replace("search", "");
    
                        txt2Speech.speak("searching " + v2txt, TextToSpeech.QUEUE_FLUSH, null);
    
                        Intent search = new Intent(Intent.ACTION_WEB_SEARCH);
                        search.putExtra(SearchManager.QUERY, v2txt);
                        startActivity(search);
                    }