在webview的应用程序中更改getPackageName(),但工作正常

时间:2016-04-09 19:22:53

标签: android webview webkit

来自how to modify the value of the key 'X-requested-with' in the request headers of resource request in Android webview, but not a page request?的答案工作正常,但我不知道如何知道getPackageName()方法的调用是否来自webkit。这是我的代码:

package com.xxx.xxx;
import android.app.Application;

public class Global extends Application {

    private static Global instance; 

    public Global() { 
        instance = this; 
    } 

    private final String PACKAGE="com.webnews.appdirector";

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public String getPackageName() {
        return PACKAGE;  //this work fine, but how to know if is webkit callback ??? "instance" have mcomponentcallbacks set to webkit, but how to read it ???
    }
}

我可以使用debug" mcomponentcallbacks" "实例"很好的#34; webkit"但我不知道怎么读。

你能帮助我吗?

1 个答案:

答案 0 :(得分:0)

尝试从线程检查堆栈跟踪:

    StackTraceElement[] stack = Thread.currentThread().getStackTrace();
    for (StackTraceElement element : stack) {
        System.out.println ("\t" + element);
    }     

结果:

lsk.test.Global.getPackageName(Global.java:43)
android.content.ContextWrapper.getPackageName(ContextWrapper.java:133)
org.chromium.base.BuildInfo.getPackageVersionName(BuildInfo.java:92)
org.chromium.content.browser.BrowserStartupController.nativeSetCommandLineFlags(Native Method)
org.chromium.content.browser.BrowserStartupController.access$700(BrowserStartupController.java:40)
android.webkit.WebView.<init>(WebView.java:606)
android.webkit.WebView.<init>(WebView.java:542)