Android calls browser open URLs encountered problems

Source: Internet
Author: User
Tags try catch

My own phone (one add-on, upgrade the hydrogen OS), then click on a "Privacy policy" in the game--need to open a webpage and then crash. The error message is as follows:

It was completely invisible, and then I wrote a demo to test the code and found the details of the error:

09-29 11:45:27.576:e/androidruntime (17871): Android.content.ActivityNotFoundException:No Activity found to handle Intent {act=android.intent.action.view cat=[android.intent.category.browsable] dat=http://url typ=text/html}

Not able to respond to the specified intent activity, but my phone to view the subscription number of the article, click on the upper right corner "open in the browser", is can pop-up to select the browser interface, normal.

A total of a few pieces of code, I analyzed, and then found the problem:

@Override
protectedvoidOnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);

Button Btnopenbrowser = (button) Findviewbyid (R.id.btn_open_browser);
Btnopenbrowser.setonclicklistener (NewOnclicklistener () {
@Override
PublicvoidOnClick (View v) {
//TODO auto-generated method stub
LOG.I ("Meteoric","click");

String strURL ="Http://cdn.haowanyou.com/mobile/comm/gtqz/yhxy.html";

Uri uri = Uri.parse (strURL);

Intent Intent =NewIntent (Intent.action_view);
Intent.addcategory (intent.category_browsable);

Intent.setdata (URI);
//Intent.setdataandtype (URI, "text/html");

StartActivity (Intent);
}
});
}

The code that is commented out is the place that produces crash, the change place is to replace Setdataandtype method with SetData. When the specified MIME type is text/html, no activity can respond. The DAT is followed by a parameter called Typ, which means that no activity can capture the intent of Typ as text/html.

In fact, it is best when startactivity, can try catch, when the specified Mimie type is a mailbox, the phone is not installed on the mailbox client will be crash. In view of the MIME problem, I temporarily just removed the type, the company test group over 5.0 of the device test is not my problem, not sure is the problem of hydrogen OS, or all 5.0 systems are so, interested students can self-test.

Android calls browser open URLs encountered problems

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.