本机脚本重写getPackageName

问题描述

我正在开发一个使用webview的android应用程序。但是,Web视图始终将X-requested-with添加到所有请求中。

据我了解,我遇到了这个https://github.com/mozilla-mobile/focus-android/issues/1196#issuecomment-638765364,其中指出如果您在应用程序中覆盖getPackageName函数,那么它将起作用。

现在,在我的本机脚本应用程序中,我添加文件application.android.js,已比AndroidManifext更改并运行了。在这文件中,我做了以下

// the first parameter of the `extend` call defines the package and the name for the native *.JAVA file generated.
android.app.Application.extend("com.name.app",{
    onCreate: function() {
        superProto.onCreate.call(this);

        // At this point modules have already been initialized
        console.log('hererere')
        // Enter custom initialization code here
    },attachBaseContext: function(base) {
        superProto.attachBaseContext.call(this,base);
        // This code enables MultiDex support for the application (if needed compile androidx.multidex:multidex)
        // androidx.multidex.MultiDex.install(this);
    },getPackageName: function(){
        console.log("getting packagee name")
        try {
            let stackTrace = java.lang.Thread.currentThread().getStackTrace();
            console.log(stackTrace)
            for (var i = 0; i< stackTrace.length ; i++) {
                let element = stackTrace[i]
                console.log("\t" + element.getClassName(),element.getmethodName());
                if ("org.chromium.base.BuildInfo".toLowerCase() === element.getClassName().toLowerCase()) {
                    if ("getAll".toLowerCase() === (element.getmethodName()).toLowerCase()) {
                        customPackageName = "";
                        return customPackageName;
                    }
                    break;
                }
            }
        } catch (e) {
            console.log(e)

         }
        

        return "com.name.app"
      
    }
});

我在此文件中看到一些对getPackageName的请求。但是这些都不是来自浏览器的。这个对吗?我错过了什么吗?实现该目标的方式应该是什么。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)