Android Example Hide Packagename and UserAgent on Webview

Hi all.
I found this example in some old folders on my pc and decided to share here.
it is a simple example of how hide the packagename and a user agent on a webview.

This example use the code snippet of @MarcoRome
https://www.b4x.com/android/forum/threads/modify-headers-in-webview.56807/#content

with some modifications.
on @MarcoRome the final request send the android user agent, and with this example the user agent is fixed on final request too.

B4X:
    'IMPORTANT HIDE PACKAGENAME
    Dim m As Map
    m.Initialize
    m.Put("User-Agent",userAgent)
    m.Put("X-Requested-With", "com.app.test"&Rnd(99,9999))
    
    
    'IMPORTANT HIDE USER AGENT
    Dim r As Reflector
    r.Target = WebView1
    r.Target = r.RunMethod("getSettings")
    r.RunMethod2("setUserAgentString", userAgent, "java.lang.String")

to test it on php
PHP:
<?php

function getRequestHeaders() {
    $headers = array();
    foreach($_SERVER as $key => $value) {
        if (substr($key, 0, 5) <> 'HTTP_') {
            continue;
        }
        $header = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))));
        $headers[$header] = $value;
    }
    return $headers;
}

$headers = getRequestHeaders();

foreach ($headers as $header => $value) {
    echo "$header: $value <br />\n";
}

?>
 

Attachments

  • esconderwebview.zip
    243.6 KB · Views: 515
Top