android端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

120 lines
4.6 KiB

  1. package com.nsgk.ruralWeb;
  2. import android.annotation.SuppressLint;
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.view.KeyEvent;
  6. import android.view.ViewGroup;
  7. import android.webkit.WebSettings;
  8. import android.webkit.WebView;
  9. import android.widget.LinearLayout;
  10. import android.widget.RelativeLayout;
  11. import com.just.agentweb.AgentWeb;
  12. import com.just.agentweb.DefaultWebClient;
  13. import androidx.annotation.Nullable;
  14. import androidx.appcompat.app.AppCompatActivity;
  15. /**
  16. * An example full-screen activity that shows and hides the system UI (i.e.
  17. * status bar and navigation/system bar) with user interaction.
  18. */
  19. public class FullscreenActivity extends AppCompatActivity {
  20. private WebView mWebView;
  21. private SensorManagerHelper sensorManagerHelper;
  22. private BaseWebChromeClient chromeClient;
  23. private String[] urls = new String[]{
  24. "http://116.255.135.38:86/authenticRight/login", "http://116.255.135.38:89/homestead/login "
  25. };
  26. private AgentWeb mAgentWeb;
  27. @SuppressLint("SetJavaScriptEnabled")
  28. @Override
  29. protected void onCreate(Bundle savedInstanceState) {
  30. super.onCreate(savedInstanceState);
  31. setContentView(R.layout.activity_fullscreen);
  32. // init();
  33. mAgentWeb = AgentWeb.with(this)//
  34. .setAgentWebParent((RelativeLayout) findViewById(R.id.ll), -1, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))//传入AgentWeb的父控件。
  35. .useDefaultIndicator(-1, 3)//设置进度条颜色与高度,-1为默认值,高度为2,单位为dp。
  36. .setWebViewClient(new com.just.agentweb.WebViewClient() {
  37. })//WebViewClient , 与 WebView 使用一致 ,但是请勿获取WebView调用setWebViewClient(xx)方法了,会覆盖AgentWeb DefaultWebClient,同时相应的中间件也会失效。
  38. .setSecurityType(AgentWeb.SecurityType.STRICT_CHECK) //严格模式 Android 4.2.2 以下会放弃注入对象 ,使用AgentWebView没影响。
  39. .setMainFrameErrorView(R.layout.agentweb_error_page, -1) //参数1是错误显示的布局,参数2点击刷新控件ID -1表示点击整个布局都刷新, AgentWeb 3.0.0 加入。
  40. .setOpenOtherPageWays(DefaultWebClient.OpenOtherPageWays.ASK)//打开其他页面时,弹窗质询用户前往其他应用 AgentWeb 3.0.0 加入。
  41. .interceptUnkownUrl() //拦截找不到相关页面的Url AgentWeb 3.0.0 加入。
  42. .createAgentWeb()//创建AgentWeb。
  43. .ready()//设置 WebSettings。
  44. .go("http://192.168.31.228:85/homesteadLogin"); //WebView载入该url地址的页面并显示。
  45. }
  46. @Override
  47. protected void onPause() {
  48. mAgentWeb.getWebLifeCycle().onPause();
  49. super.onPause();
  50. }
  51. @Override
  52. protected void onResume() {
  53. mAgentWeb.getWebLifeCycle().onResume();
  54. super.onResume();
  55. }
  56. @Override
  57. protected void onDestroy() {
  58. mAgentWeb.getWebLifeCycle().onDestroy();
  59. super.onDestroy();
  60. }
  61. @Override
  62. public boolean onKeyDown(int keyCode, KeyEvent event) {
  63. // if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {
  64. // mWebView.goBack();
  65. // return true;
  66. // }
  67. if (mAgentWeb.handleKeyEvent(keyCode, event)) {
  68. return true;
  69. }
  70. return super.onKeyDown(keyCode, event);
  71. }
  72. public void setWebSettings(WebView mView) {
  73. WebSettings setting = mView.getSettings();
  74. //支持Js
  75. setting.setJavaScriptEnabled(true);
  76. setting.setJavaScriptCanOpenWindowsAutomatically(true);
  77. //缓存模式
  78. setting.setCacheMode(WebSettings.LOAD_DEFAULT);
  79. //支持内容重新布局
  80. setting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
  81. //将图片调整到适合webview的大小
  82. setting.setUseWideViewPort(true);
  83. setting.setLoadWithOverviewMode(true);
  84. //设置可以访问文件
  85. setting.setAllowFileAccess(true);
  86. //支持自动加载图片
  87. setting.setLoadsImagesAutomatically(true);
  88. try {
  89. setting.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
  90. } catch (NoSuchMethodError e) {
  91. e.printStackTrace();
  92. }
  93. }
  94. @Override
  95. protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
  96. chromeClient.onActivityResult(requestCode, resultCode, data);
  97. super.onActivityResult(requestCode, resultCode, data);
  98. }
  99. }