如何在线搜索 [英] How to make a search online

查看:62
本文介绍了如何在线搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在线搜索特定网站上的文字。

我已经尝试了ACTION_VIEW意图,但我似乎无法搜索我正在寻找的单词。

我使用过:

I want to search for a text on a specific website online.
I have tried ACTION_VIEW intent, but I can't seem to make it search the word I am looking for.
I used:

Intent openHashURLinBrowser = new Intent(Intent.ACTION_VIEW,Uri.parse("google"));
openHashURLinBrowser.putExtra(SearchManager.QUERY,"laptop");





有人可以帮我解决这个问题吗? br />
任何帮助将不胜感激。



我尝试过:



意图openHashURLinBrowser =新意图(Intent.ACTION_WEB_SEARCH,Uri.parse(google.com));

openHashURLinBrowser.putExtra(SearchManager.QUERY,laptops) ;



Can someone please help me get this working?
any help will be greatly appreciated.

What I have tried:

Intent openHashURLinBrowser = new Intent(Intent.ACTION_WEB_SEARCH,Uri.parse("google.com"));
openHashURLinBrowser.putExtra(SearchManager.QUERY,"laptops");

推荐答案

您不能以您正在查看的方式使用Google。谷歌的服务条款禁止使用。



你必须使用他们的自定义搜索引擎API [ ^ ],而不是自由。如何设置它并不明显,因为文档一直指的是搜索您的网站,但它可以做到。请参见 [ ^ ]如何。
You cannot use Google in the manner you're looking at. It's forbidden by Google's Terms of Service.

You MUST use their Custom Search Engine API[^], and it's not free. It's not obvious how to set it up because the documentation keeps referring to "search YOUR site", but it's possible to do. See this[^] for how.


我在android studio中有一个谷歌图像搜索应用程序。它可以使用图片搜索在谷歌上搜索图像。我发现,如果我添加网站:ebay.com,amazon.com,谷歌搜索这些网站中的图像,所以我想将该字符串添加到图像搜索中,以便谷歌返回该图像的结果2个站点。

这是我用于图像搜索的代码:

I have a google image search app in android studio. It can search for an image on google, using the image search. I found out that if I add "sites:ebay.com,amazon.com", Google searches the image in those sites, so I want to add that string to the image search, so that google returns the results of that image from those 2 sites.
This is the code I have for the image search:
public class SearchGoogleIntentActivity extends ActionBarActivity
{
    private  DisplayImageOptions options = null;
    private  ImageLoader imageLoader = null;
    // Asynchronous task for fetching Google hash of image
    class GoogleImageHashJob extends AsyncTask<Bitmap, Void, Integer>
    {
        @Override
        protected Integer doInBackground(Bitmap[] bitmap)
        {
            try
            {
                // Send bitmap to google hash server
                String hash = GoogleImageHash.hashFromBitmap(bitmap[0]);

                // Send hash link to browser
                Intent openHashURLinBrowser = new Intent(Intent.ACTION_VIEW);
                openHashURLinBrowser.setData(Uri.parse(hash+"Sites:ebay.com,amazon.com"));

                startActivityForResult(openHashURLinBrowser, 0);
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }

            return 0;
        }

        // Close splash screen after hash has been fetched and browser intent sent
        @Override
        protected void onPostExecute(Integer result)
        {
            if (result == 0)
                SearchGoogleIntentActivity.this.finish();
        }
    }

    // Load splash screen
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // Setup activity
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reverse_image_search_google);

        // Load intent
        Intent intent = getIntent();
        Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);

//        Toast.makeText(this, imageUri.toString(), Toast.LENGTH_LONG).show();

        // Load image

        ImageView imageView = (ImageView) findViewById(R.id.imageView);

        imageLoader = ImageLoader.getInstance();
        ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(this));

        options = new DisplayImageOptions.Builder()
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .considerExifParams(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .build();
        imageLoader.displayImage(imageUri.toString(), imageView, options, null);


        Bitmap bitmap = ImageLoader.getInstance().loadImageSync(imageUri.toString());
//        imageView.setImageBitmap(bitmap);

        // Run hash job
        GoogleImageHashJob job = new GoogleImageHashJob();
        job.execute(bitmap);
    }

/*
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_reverse_image_search_google, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
    */

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);


    }
}





即使我添加了在解析uri中哈希后的字符串,我只是从谷歌获取图像搜索结果,并没有我添加的网站的结果。

有人可以帮助我吗?

谢谢。



The thing is that even though I added that string after hash in the parse uri, I am only getting the image search results from google, and no results from the sites I added.
Can someone please help me?
Thanks.


如何配置我的应用程序以使用google api进行网站搜索?

我看了你给的链接,但它没有没有说明如何在andoid studio中配置它。
How do I configure my app to use google api to make the search by site possible?
I looked at the link you gave, but it doesn't show how to configure it in andoid studio.


这篇关于如何在线搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆