|
|
@@ -1,16 +1,15 @@
|
|
|
package com.jld.vod.view
|
|
|
|
|
|
-import android.graphics.Bitmap
|
|
|
+import android.content.Intent
|
|
|
import android.os.Build
|
|
|
+import android.os.Bundle
|
|
|
import android.view.KeyEvent
|
|
|
-import android.webkit.WebView
|
|
|
import android.widget.LinearLayout
|
|
|
+import androidx.appcompat.app.AppCompatActivity
|
|
|
+import androidx.fragment.app.FragmentActivity
|
|
|
import com.jld.vod.R
|
|
|
-import com.jld.vod.base.BaseActivity
|
|
|
import com.jld.vod.utils.LogUtils
|
|
|
import com.just.agentweb.AgentWeb
|
|
|
-import com.just.agentweb.WebChromeClient
|
|
|
-import com.just.agentweb.WebViewClient
|
|
|
import kotlinx.android.synthetic.main.activity_web.*
|
|
|
import java.lang.reflect.Constructor
|
|
|
import java.lang.reflect.Field
|
|
|
@@ -23,30 +22,42 @@ import java.lang.reflect.Method
|
|
|
* @description:
|
|
|
* @date :2020/7/16 14:46
|
|
|
*/
|
|
|
-class WebActivity : BaseActivity() {
|
|
|
+class WebActivity : AppCompatActivity() {
|
|
|
private var mAgentWeb: AgentWeb? = null
|
|
|
private var mLinearLayout : LinearLayout? = null
|
|
|
|
|
|
- override fun getLayoutId(): Int {
|
|
|
- return R.layout.activity_web
|
|
|
- }
|
|
|
|
|
|
- override fun initView() {
|
|
|
- super.initView()
|
|
|
+// val mWebViewClient: WebViewClient = object : WebViewClient() {
|
|
|
+// override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
|
|
|
+// LogUtils.logD("url=="+url)
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// val mWebChromeClient: WebChromeClient = object : WebChromeClient() {
|
|
|
+// override fun onProgressChanged(view: WebView?, newProgress: Int) {
|
|
|
+// //LogUtils.logD("newProgress=="+newProgress)
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
+ super.onCreate(savedInstanceState)
|
|
|
+ hookWebViews()
|
|
|
+ setContentView(R.layout.activity_web)
|
|
|
+
|
|
|
val intnet = intent
|
|
|
val url = intnet.getStringExtra("url")
|
|
|
- hookWebView()
|
|
|
+
|
|
|
|
|
|
mLinearLayout = findViewById(R.id.ll_webview)
|
|
|
|
|
|
mAgentWeb = AgentWeb.with(this)
|
|
|
- .setAgentWebParent(mLinearLayout!!, LinearLayout.LayoutParams(-1, -1))
|
|
|
- .useDefaultIndicator(-1,6)
|
|
|
- .setWebChromeClient(mWebChromeClient)
|
|
|
- .setWebViewClient(mWebViewClient)
|
|
|
- .createAgentWeb()
|
|
|
- .ready()
|
|
|
- .go(url)
|
|
|
+ .setAgentWebParent(mLinearLayout!!, LinearLayout.LayoutParams(-1, -1))
|
|
|
+ .useDefaultIndicator(-1,6)
|
|
|
+// .setWebChromeClient(mWebChromeClient)
|
|
|
+// .setWebViewClient(mWebViewClient)
|
|
|
+ .createAgentWeb()
|
|
|
+ .ready()
|
|
|
+ .go(url)
|
|
|
|
|
|
//后退
|
|
|
iv_web_back.setOnClickListener {
|
|
|
@@ -64,11 +75,12 @@ class WebActivity : BaseActivity() {
|
|
|
//退出
|
|
|
iv_web_exit.setOnClickListener {
|
|
|
this.onBackPressed()
|
|
|
+ // System.exit(0)
|
|
|
}
|
|
|
|
|
|
//回到主界面
|
|
|
iv_web_home.setOnClickListener {
|
|
|
- go<HomeActivity>()
|
|
|
+ startActivity(Intent(this,HomeActivity::class.java))
|
|
|
finish()
|
|
|
}
|
|
|
|
|
|
@@ -78,19 +90,6 @@ class WebActivity : BaseActivity() {
|
|
|
webview.reload() //刷新
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- val mWebViewClient: WebViewClient = object : WebViewClient() {
|
|
|
- override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
|
|
|
- LogUtils.logD("url=="+url)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- val mWebChromeClient: WebChromeClient = object : WebChromeClient() {
|
|
|
- override fun onProgressChanged(view: WebView?, newProgress: Int) {
|
|
|
- //LogUtils.logD("newProgress=="+newProgress)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
override fun onPause() {
|
|
|
mAgentWeb!!.webLifeCycle.onPause()
|
|
|
super.onPause()
|
|
|
@@ -102,8 +101,8 @@ class WebActivity : BaseActivity() {
|
|
|
}
|
|
|
|
|
|
override fun onDestroy() {
|
|
|
- super.onDestroy()
|
|
|
mAgentWeb!!.webLifeCycle.onDestroy()
|
|
|
+ super.onDestroy()
|
|
|
}
|
|
|
|
|
|
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
|
|
@@ -114,9 +113,11 @@ class WebActivity : BaseActivity() {
|
|
|
private fun hookWebView() {
|
|
|
var factoryClass: Class<*>? = null
|
|
|
try {
|
|
|
+
|
|
|
factoryClass = Class.forName("android.webkit.WebViewFactory")
|
|
|
var getProviderClassMethod: Method? = null
|
|
|
var sProviderInstance: Any? = null
|
|
|
+ LogUtils.logD("Build.VERSION.SDK_INT="+Build.VERSION.SDK_INT)
|
|
|
if (Build.VERSION.SDK_INT === 23) {
|
|
|
getProviderClassMethod = factoryClass.getDeclaredMethod("getProviderClass")
|
|
|
getProviderClassMethod.setAccessible(true)
|
|
|
@@ -161,4 +162,39 @@ class WebActivity : BaseActivity() {
|
|
|
e.printStackTrace()
|
|
|
}
|
|
|
}
|
|
|
+ fun hookWebViews() {
|
|
|
+ val sdkInt = Build.VERSION.SDK_INT
|
|
|
+ try {
|
|
|
+ val factoryClass = Class.forName("android.webkit.WebViewFactory")
|
|
|
+ val field = factoryClass.getDeclaredField("sProviderInstance")
|
|
|
+ field.isAccessible = true
|
|
|
+ var sProviderInstance = field[null]
|
|
|
+ if (sProviderInstance != null) {
|
|
|
+ LogUtils.logD("sProviderInstance isn't null")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ val getProviderClassMethod: Method
|
|
|
+ getProviderClassMethod = if (sdkInt > 22) {
|
|
|
+ factoryClass.getDeclaredMethod("getProviderClass")
|
|
|
+ } else if (sdkInt == 22) {
|
|
|
+ factoryClass.getDeclaredMethod("getFactoryClass")
|
|
|
+ } else {
|
|
|
+ LogUtils.logD( "Don't need to Hook WebView")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ getProviderClassMethod.isAccessible = true
|
|
|
+ val providerClass = getProviderClassMethod.invoke(factoryClass) as Class<*>
|
|
|
+ val delegateClass = Class.forName("android.webkit.WebViewDelegate")
|
|
|
+ val providerConstructor = providerClass.getConstructor(delegateClass)
|
|
|
+ if (providerConstructor != null) {
|
|
|
+ providerConstructor.isAccessible = true
|
|
|
+ val declaredConstructor = delegateClass.getDeclaredConstructor()
|
|
|
+ declaredConstructor.isAccessible = true
|
|
|
+ sProviderInstance = providerConstructor.newInstance(declaredConstructor.newInstance())
|
|
|
+ field["sProviderInstance"] = sProviderInstance
|
|
|
+ }
|
|
|
+ LogUtils.logD( "Hook done!")
|
|
|
+ } catch (e: Throwable) {
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|