Add fake context
This commit is contained in:
parent
9325d584b0
commit
742629c01a
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.github.catvod.hook;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.ContextWrapper;
|
||||||
|
|
||||||
|
public class Ctx extends ContextWrapper {
|
||||||
|
|
||||||
|
public Ctx(Context base) {
|
||||||
|
super(base);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPackageName() {
|
||||||
|
return "com.android.chrome";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,7 @@ import android.os.Looper;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.github.catvod.crawler.SpiderDebug;
|
import com.github.catvod.crawler.SpiderDebug;
|
||||||
|
import com.github.catvod.hook.Ctx;
|
||||||
import com.github.catvod.utils.Trans;
|
import com.github.catvod.utils.Trans;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
@ -38,6 +39,10 @@ public class Init {
|
||||||
return get().app;
|
return get().app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Context fakeCtx() {
|
||||||
|
return new Ctx(get().app);
|
||||||
|
}
|
||||||
|
|
||||||
public static void init(Context context) {
|
public static void init(Context context) {
|
||||||
SpiderDebug.log("自定義爬蟲代碼載入成功!");
|
SpiderDebug.log("自定義爬蟲代碼載入成功!");
|
||||||
get().app = ((Application) context);
|
get().app = ((Application) context);
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,7 @@ public class Utils {
|
||||||
|
|
||||||
public static void loadWebView(String url, WebViewClient client) {
|
public static void loadWebView(String url, WebViewClient client) {
|
||||||
Init.run(() -> {
|
Init.run(() -> {
|
||||||
WebView webView = new WebView(Init.context());
|
WebView webView = new WebView(Init.fakeCtx());
|
||||||
webView.getSettings().setDatabaseEnabled(true);
|
webView.getSettings().setDatabaseEnabled(true);
|
||||||
webView.getSettings().setDomStorageEnabled(true);
|
webView.getSettings().setDomStorageEnabled(true);
|
||||||
webView.getSettings().setJavaScriptEnabled(true);
|
webView.getSettings().setJavaScriptEnabled(true);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue