微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

本机脚本重写getPackageName

如何解决本机脚本重写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 举报,一经查实,本站将立刻删除。