android 浏览器开技术

1.网页内的右键菜单

[java] view plain copy
  1. publicbooleanonLongClick(Viewview){
  2. //获取点击的元素
  3. HitTestResultmResult=mWebView.getHitTestResult();
  4. finalinttype=mResult.getType();
  5. switch(type){
  6. caseHitTestResult.ANCHOR_TYPE:
  7. caseHitTestResult.SRC_ANCHOR_TYPE:
  8. //点击的是链接
  9. break;
  10. caseHitTestResult.IMAGE_TYPE:
  11. caseHitTestResult.IMAGE_ANCHOR_TYPE:
  12. caseHitTestResult.SRC_IMAGE_ANCHOR_TYPE:
  13. //点击的是图片
  14. break;
  15. default:
  16. //点击的是空白处
  17. break;
  18. }
  19. returntrue;
  20. }

根据是图片还是链接还是空白做判断


2.网页内的自由复制

转载请注明出处:http://blog.csdn.net/ethan_xue/article/details/7748075


[java] view plain copy
  1. /**
  2. *网页里复制粘贴
  3. *@paramviewwebView
  4. *@authorethan
  5. */
  6. privatevoidemulateShiftHeld(KeyEvent.Callbackview)
  7. {
  8. try
  9. {
  10. KeyEventshiftPressEvent=newKeyEvent(0,0,KeyEvent.ACTION_DOWN,
  11. KeyEvent.KEYCODE_SHIFT_LEFT,0,0);
  12. shiftPressEvent.dispatch(view);
  13. }catch(Exceptione)
  14. {
  15. }
  16. }

3.出错界面

webkit自带的出错界面不够霸气,于是改为自己做的出错界面

[java] view plain copy
  1. newWebViewClient()
  2. ...此为背景
  3. @Override
  4. publicvoidonReceivedError(WebViewview,interrorCode,
  5. Stringdescription,StringfailingUrl){
  6. view.stopLoading();
  7. view.clearView();
  8. //显示出错界面
  9. mWebView.loadUrl("file:///android_asset/error.html");
  10. }

4.点外部链接调用自己的浏览器

在manifest.xml里主activity加入intent

[html] view plain copy
  1. <pstyle="color:rgb(51,51,51);font-family:Arial;font-size:16px;line-height:25px;text-align:left;"><!--FortheseschemeswerenotparticularMIMEtypehasbeen
  2. supplied,weareagoodcandidate.-->
  3. <intent-filter>
  4. <actionandroid:name="android.intent.action.VIEW"/>
  5. <categoryandroid:name="android.intent.category.DEFAULT"/>
  6. <categoryandroid:name="android.intent.category.BROWSABLE"/>
  7. <dataandroid:scheme="http"/>
  8. <dataandroid:scheme="https"/>
  9. <dataandroid:scheme="about"/>
  10. <dataandroid:scheme="javascript"/>
  11. </intent-filter>
  12. <!--FortheseschemeswhereanyoftheseparticularMIMEtypes
  13. havebeensupplied,weareagoodcandidate.-->
  14. <intent-filter>
  15. <actionandroid:name="android.intent.action.VIEW"/>
  16. <categoryandroid:name="android.intent.category.BROWSABLE"/>
  17. <categoryandroid:name="android.intent.category.DEFAULT"/>
  18. <dataandroid:scheme="http"/>
  19. <dataandroid:scheme="https"/>
  20. <dataandroid:scheme="inline"/>
  21. <dataandroid:mimeType="text/html"/>
  22. <dataandroid:mimeType="text/plain"/>
  23. <dataandroid:mimeType="application/xhtml+xml"/>
  24. <dataandroid:mimeType="application/vnd.wap.xhtml+xml"/>
  25. </intent-filter>
  26. <actionandroid:name="android.intent.action.VIEW"/>
  27. <categoryandroid:name="android.intent.category.DEFAULT"/>
  28. <categoryandroid:name="android.intent.category.BROWSABLE"/>
  29. <dataandroid:scheme="file"/>
  30. </intent-filter></p>

外部调用就ok了,连file文件都能调用,若自己调用的话

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值