Start Google search query from activity - Android

后端 未结 5 1591
情书的邮戳
情书的邮戳 2020-12-14 08:42

I was wondering if there is an easier way (or any way) to start a Browser with a Google search query. For example user can select a certain word or phrase and click a button

5条回答
  •  半阙折子戏
    2020-12-14 09:26

                    String Search= null;
                    try {
                        Search= URLEncoder.encode(s, "UTF-8");
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
                    Uri uri = Uri.parse("http://www.google.com/#q=" + Search);
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                }
            });
    

提交回复
热议问题