'How to add URL to an image in android studio?

I want in my app that when someone clicks the image it opens with the default browser.

I have searched everywhere but no method helps me.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".Home_Activity"
android:background="#FF0000">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/AppTitleimage1"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:src="@mipmap/fra"
    android:contentDescription="@string/AppTitleImageS"
    android:autoLink="web"
    android:clickable="true" />

How can I add a link to an image that opens in a default browser

Thanks

So I found this:

ImageView imgLink=(ImageView)findViewById(R.id.weblink);
    imgLink.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent link=new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
            startActivity(link);    
        }
    });

But when I paste it in my java class it says:

"Cannot resolve method 'findViewById'(?) and "cannot resolve symbol 'weblink' and "cannot resolve method startActivity(android.content.intent)

My question is different and that answer is not working



Solution 1:[1]

you can implement onClick for imageView and can open url from there:

example:

ImageView imageView = (ImageView) findViewById(R.id.AppTitleimage1);
imageView.setOnClickListener(new View.OnClickListener() {  
        public void onClick(View v)
            {
                Uri uri = Uri.parse("http://www.google.com"); 
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent); 
            }
         });

Solution 2:[2]

ImageView imgLink=(ImageView)findViewById(R.id.AppTitleimage1);
imgLink.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        String url = "http://www.example.com";
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);   
    }
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rahul Tiwari
Solution 2 Nimantha