Introduction
In this article, I have explained the VPN connection via VPNHood in Xamarin.Android. Undetectable VPN for ordinary users and experts. VpnHood is a solution to bypass Advanced Firewall and can circumvent deep packet inspection. VpnHood has been created from scratch entirely in C#.
Server Features
- No Network configuration or knowledge is required
- No Admin privilege is required
- Built-In User Management
- Built-In NAT with zero configuration
- Run on any Windows 7,8,10 or Windows Server
- Run on Linux
Requirement
Install-Package VpnHood.Client -Version 1.2.250
Install-Package VpnHood.Client.App -Version 1.1.235
Step 1
Create a new class name like AndroidApp.cs and implementing the Application, IAppProvider Interface to connect the vpnhood server.
public class AndroidApp: Application, IAppProvider {
public static AndroidApp Current {
get;
private set;
}
private VpnHoodApp VpnHoodApp {
get;
set;
}
public IDevice Device {
get;
}
public AndroidApp(IntPtr javaReference, JniHandleOwnership transfer): base(javaReference, transfer) {
Device = new AndroidDevice();
}
public override void OnCreate() {
base.OnCreate();
VpnHoodApp = VpnHoodApp.Init(this, new AppOptions {});
Current = this;
}
protected override void Dispose(bool disposing) {
if (disposing) {
VpnHoodApp?.Dispose();
VpnHoodApp = null;
}
base.Dispose(disposing);
}
}
Step 2
After creating the Vpn hood connection, call the VPN server via webview to connect the public server and Undetectable vpn to bypass Advanced Firewall and can circumvent deep packet inspection.
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity: AppCompatActivity {
public WebView WebView {
get;
private set;
}
private VpnHoodAppUI _appUi;
private
const int REQUEST_VpnPermission = 10;
private AndroidDevice Device => (AndroidDevice) AndroidApp.Current.Device;
protected override void OnCreate(Bundle savedInstanceState) {
try {
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
SetContentView(Resource.Layout.activity_main);
Device.OnRequestVpnPermission += Device_OnRequestVpnPermission;
_appUi = VpnHoodAppUI.Init(Resources.Assets.Open("SPA.zip"));
InitWebUI();
} catch (Exception ex) {}
}
private void Device_OnRequestVpnPermission(object sender, System.EventArgs e) {
var intent = VpnService.Prepare(this);
if (intent == null) {
Device.VpnPermissionGranted();
} else {
StartActivityForResult(intent, REQUEST_VpnPermission);
}
}
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data) {
if (requestCode == REQUEST_VpnPermission && resultCode == Result.Ok) Device.VpnPermissionGranted();
else Device.VpnPermissionRejected();
}
protected override void OnDestroy() {
Device.OnRequestVpnPermission -= Device_OnRequestVpnPermission;
_appUi.Dispose();
_appUi = null;
base.OnDestroy();
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) {
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
public void InitWebUI() {
var webViewClient = new MyWebViewClient();
webViewClient.PageLoaded += WebViewClient_PageLoaded;
WebView = new WebView(this);
WebView.SetWebViewClient(webViewClient);
WebView.Settings.JavaScriptEnabled = true;
WebView.Settings.DomStorageEnabled = true;
WebView.Settings.JavaScriptCanOpenWindowsAutomatically = true;
WebView.SetLayerType(LayerType.Hardware, null);
WebView.SetWebContentsDebuggingEnabled(true);
WebView.LoadUrl($ "{_appUi.Url}?nocache={_appUi.SpaHash}");
}
private void WebViewClient_PageLoaded(object sender, System.EventArgs e) {
SetContentView(WebView);
Window.SetStatusBarColor(new Color(0x19, 0x40, 0xb0));
}
public override void OnBackPressed() {
if (WebView.CanGoBack()) WebView.GoBack();
else base.OnBackPressed();
}
}
Step 3
The final step to copy-paste the attached SAP.Zip files in the project assets folder to access the public server.
Output
![]()
Hopefully, this article has given you sufficient information for you to start creating your vpnhood server in your Xamarin.Android application. Feel free to leave a comment if you would like me to further elaborate on anything within this article.