Tips for Android browser Development

Source: Internet
Author: User

My friends and I have made a browser for some time. I will share some tips, write some of them first, write them slowly, and advertisement our browser.

Our browser is coming online, called sofa Browser

1. Right-click menu on the webpage

Public Boolean onlongclick (view) {// gets the clicked element hittestresult mresult = mwebview. gethittestresult (); Final int type = mresult. getType (); Switch (type) {Case hittestresult. anchor_type: Case hittestresult. src_anchor_type: // click the link break; Case hittestresult. image_type: Case hittestresult. image_anchor_type: Case hittestresult. src_image_anchor_type: // The image break is clicked; default: // the blank space break is clicked;} return true ;}

Determine whether the image is an image, link, or blank

2. Free copy on the webpage

Reprinted please indicate the source: http://blog.csdn.net/ethan_xue/article/details/7748075

/*** Copy and paste * @ Param view webview * @ author Ethan */private void emulateshiftheld (keyevent. callback view) {try {keyevent shiftpressevent = new keyevent (0, 0, keyevent. action_down, keyevent. keycode_shift_left, 0, 0); shiftpressevent. dispatch (view);} catch (exception e ){}}

3. Error Page

The error interface provided by WebKit is not domineering enough, so it is changed to an error interface made by myself.

New webviewclient ()... this is the background @ overridepublic void onreceivederror (webview view, int errorcode, string description, string failingurl) {view. stoploading (); view. clearview (); // display the error page mwebview. loadurl ("file: // android_asset/error.html ");}

4. Click an external link to call your browser.

Add intent to the main activity in manifest. xml

<!-- For these schemes were not particular MIME type has been                 supplied, we are a good candidate. -->            <intent-filter>                <action android:name="android.intent.action.VIEW" />                <category android:name="android.intent.category.DEFAULT" />                <category android:name="android.intent.category.BROWSABLE" />                <data android:scheme="http" />                <data android:scheme="https" />                <data android:scheme="about" />                <data android:scheme="javascript" />            </intent-filter>            <!--  For these schemes where any of these particular MIME types                  have been supplied, we are a good candidate. -->            <intent-filter>                <action android:name="android.intent.action.VIEW" />                <category android:name="android.intent.category.BROWSABLE" />                <category android:name="android.intent.category.DEFAULT" />                <data android:scheme="http" />                <data android:scheme="https" />                <data android:scheme="inline" />                <data android:mimeType="text/html"/>                <data android:mimeType="text/plain"/>                <data android:mimeType="application/xhtml+xml"/>                <data android:mimeType="application/vnd.wap.xhtml+xml"/>            </intent-filter>                <action android:name="android.intent.action.VIEW" />                <category android:name="android.intent.category.DEFAULT" />                <category android:name="android.intent.category.BROWSABLE" />                <data android:scheme="file" />            </intent-filter>

The external call is OK, and the file can be called, if you call it yourself

Uri uri = Uri.parse("file://data/data/test.html");//   Uri uri = Uri.parse("http://m.baidu.com");       Intent it = new Intent(Intent.ACTION_VIEW, uri);          context.startActivity(it);     

Related Article

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.