首页 > 解决方案 > Android Studio ...在意图中将查询值传递给互联网搜索

问题描述

以下代码与 onClickListener 一起使用以打开 YouTube,并且应该传递查询值。

        String Query = MOVENAME.toString();
        Uri uri = Uri.parse("http://www.youtube.com/#q=" );
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        intent.putExtra("query", Query ); 
        startActivity(intent);
        try {
            this.startActivity(intent);
        } catch 

但是,它只会打开 YouTube……但如果我将其替换为……

intent.putExtra("query", "anything I want to search for" ); <-note text surrounded by " " 

然后它会根据输入的文本运行搜索。

关于如何以可行的格式将存储在 MOVENAME 中的 EditText 信息传递给意图的任何建议?

标签: javaandroidandroid-studio

解决方案


更正....字符串查询 = MOVENAME.getText().toString();

忽略了所需的 .getText() 并且传递的是对象而不是内容。


推荐阅读