2

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.

jradich1234
  • 1,410
  • 5
  • 24
  • 29
KISHORE_ZE
  • 1,466
  • 3
  • 16
  • 26
  • Have you encoded the query to URL encoding (eg. "my big dog" would be "my+big+dog")? I believe there's a Java class (URLEncode?) to do that. It might not solve your original problem, but it sure will solve future problems. – kkirigaya Oct 14 '15 at 20:43
  • 1
    @kkirigaya I'll try this and let you know soon. Also thanks for the reply – KISHORE_ZE Oct 15 '15 at 07:07
  • 1
    @kkirigaya also the only main differences in the 2 parts are that 'Yahoo' is replaced as bing but I know the `if` statement works. The second is that the 2 `url`'s are different. So maybe if I add in the yahoo part an `+ ""` would it work. I am not sure. However I will definitely try your suggestion and my idea and let you know soon. Thanks. – KISHORE_ZE Oct 15 '15 at 07:09
  • 1
    Oh My Gods! 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 is the question had a mistake. – KISHORE_ZE Oct 15 '15 at 08:21

1 Answers1

0

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);
                } 
KISHORE_ZE
  • 1,466
  • 3
  • 16
  • 26