-1

I want to create an android app. When I click a row in the ListView, it should go to a website.

In the ListView I'll have my widgets such as TextView, ImageView etc... For eg: "www.amazon.com"

I tried the following,

rowView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.EMPTY.parse("www.amazon.com"));
            context.startActivity(i);
        }
    });

It successfully redirects to "www.amazon.com".

Here, how will the amazon people know that people are visiting their website using my app?

Bö macht Blau
  • 12,820
  • 5
  • 40
  • 61
Gnik
  • 7,120
  • 20
  • 79
  • 129

2 Answers2

2

When you click a link, your browser loads the web page you clicked and tells the website where you came from. For example, if you clicked a link to an outside website on stackoverflow.com, the outside website would see the address of the stackoverflow.com question you came from. This information is contained in the HTTP referrer header.

To add this information you can use the following code, assuming you are using a WebView to display the website

 String url = "http://www.amazon.com/";
 Map<String, String> extraHeaders = new HashMap<String, String>();
 extraHeaders.put("Referer", "http://www.yourwebsite.com");
 WebView wv;
 wv = (WebView) findViewById(R.id.webview);
 wv.loadUrl(url, extraHeaders); 

Using an Intent is not possible with the exception the user would use the default browser which supports this kind of code

    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    Bundle bundle = new Bundle(); 
    bundle.putString("Referer", "http://www.yourwebsite.com"); 
    browserIntent.putExtra(Browser.EXTRA_HEADERS, bundle);

However if you simply have the WebView in your layout, with visibility invisible, and you do not overwrite the WebClient, i.e.wv.setWebViewClient(new MyWebViewClient());, you get the same behaviour as with the Intent

Radu Ionescu
  • 3,462
  • 5
  • 24
  • 43
  • Thanks Radu. May be my question was wrong. But I will have values in the list view. So if I click a row in the list it should go to a website. In every row I'll have my own textview, imageview. Could you assist in such scenario? – Gnik Jan 18 '16 at 12:58
0

I've never worked with android apps so I don't know the exact implementation. But what you could do is setting the header of your webrequest manually so you look like a desktopbrowser. If you're using chrome as a browser you can see what your headers are in the developers tools window under network

blipman17
  • 523
  • 3
  • 23