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);