0

I am trying to open a link in the browser on click of an imageview inside a recycler view in android. I have logged all the links that are coming and they all have https:// at the start. I get exception:

android.content.ActivityNotFoundException: No Activity found to handle Intent

I have tried reading the related questions but none helped. My onClick() code is:

 public void onClick(View v) {

            String url = mTitleList.get(getAdapterPosition());
            Intent intent  = new Intent();
            intent.setAction(Intent.ACTION_VIEW);

          // intent.addCategory(Intent.CATEGORY_BROWSABLE);

            //pass the url to intent data
            intent.setData(Uri.parse(url));
            startActivity(intent);


        }
TestStart
  • 93
  • 1
  • 9
  • check in androidmanifest.xml, your activity is not there – MinnuKaAnae Aug 03 '17 at 10:45
  • check this [No Activity found to handle Intent error](https://stackoverflow.com/questions/41548209/android-no-activity-found-to-handle-intent-when-opening-fb-native-app/41548299#41548299) – Sagar Gangawane Aug 03 '17 at 10:46
  • Possible duplicate of [How can I open a URL in Android's web browser from my application?](https://stackoverflow.com/questions/2201917/how-can-i-open-a-url-in-androids-web-browser-from-my-application) – 323go Aug 03 '17 at 10:47

3 Answers3

1

In Some case url starts with "www". That's why we get Activity not found to handle Intent exception.
You can try this.

if (!url.startsWith("https://") && !url.startsWith("http://")){
    url = "http://" + url;
}
Intent openUrlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(openUrlIntent);
Rohit Singh
  • 11,804
  • 4
  • 65
  • 66
Saurabh Bhandari
  • 280
  • 2
  • 11
-1

first make sure url is vaild, print it in logcat and open it in ur browser and check.

then try this:

Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
Alaa AbuZarifa
  • 851
  • 10
  • 32
  • This code is equivalent to what OP already has. The suggestion should be a comment instead as it does not solve the problem. – Eugen Pechanec Aug 03 '17 at 11:13
-1
textView_facebook.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("your link"));
                startActivity(browserIntent);
            }
        });
Bugs
  • 4,356
  • 9
  • 30
  • 39
Kishan Viramgama
  • 713
  • 1
  • 9
  • 18