Click here to Skip to main content
15,889,429 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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");


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");
Posted
Updated 30-Dec-16 7:19am
Comments
Richard MacCutchan 30-Dec-16 12:08pm    
Two lines of code does not explain what is not working.

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.
 
Share this answer
 
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);


    }
}


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.
 
Share this answer
 
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.
 
Share this answer
 
v2
Once I have added the google search api, can I add the sites programatically? If so, please tell me how.
Thanks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900