dev7dev / V2ray-Android

A simple Java module with sample source for implementing V2ray/Xray on Android.
37 stars 12 forks source link
android android-studio v2ray xray-core

V2ray-Example

A simple Java module with sample source code to implement the v2ray on Android.
This module is built from a custom library based on the xray core . With this module, you can easily develop your VPN application based on powerful v2ray protocols. This module currently supports v2ray short links (URI) thanks to a custom library (may have bugs).
In fact, this module provides you a v2ray client with xray core, which you can manage with static functions in V2rayController .

:exclamation: The function of the library to convert uri to json may have a bug. Test before using in production.

Sample Application You can download sample release of this module from Github Releases of this repo

v2ray android java v2ray android java

Build

Before anything, make sure you are using the latest version of Android Studio. The sample project does not use any special dependencies or tools, so if there are no network or software issues on your system, you can simply clone it and build it in Android Studio with one click.

Implementation

Note : The contents of the manifest of your main project will be automatically merged with the contents of the library monifest, so there is no need to manually copy the contents.

Usage

  • First, the library needs to be initialized. So call this function for this purpose in the primary methods of your activity.
    V2rayController.init(this, R.drawable.ic_launcher, "V2ray Android");

    R.drawable.ic_launcher is a drawable resource that will be used in vpn notification. "V2ray Android" is application name

  • You can get the version of core with this
    V2rayController.getCoreVersion()
  • With this function you will get current status of module
    V2rayController.getConnectionState()

    This will return an enum with three state : CONNECTED,CONNECTING,DISCONNECTED

  • For start a connection
    V2rayController.startV2ray(this, "Test Server", "vless:\\test@test", null);

    "Test Server" will be used as remark in notification. "vless:\\test@test" is a string of your config (could be uri or full json) null means no application package will be bypass the tunnel

  • For stop connection
    V2rayController.stopV2ray(this);

    you should call this function in main thread.

Credits