The documentation describes the steps to integrate ActSDK into your Android Studio project.
Add ActSDK.aar to your application's build.gradle file
compile(name:'ActSDK', ext:'aar')
Add VPNService.java to your application's AndroidManifest.xml file
<service> android:name="com.actmobile.actsdk.SDKVPNService" android:permission="android.permission.BIND_VPN_SERVICE"> <intent-filter> <action android:name="com.actmobile.actsdk.SDKVPNService" /> </intent-filter> </service>
Make sure the necessary permissions are included
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Initialize the SDK like below:
ActSDK actSDK = ActSDK.getInstance(); actSDK.initSDKwithToken(getApplicationContext(), MainActivity.this, <INSERT SDK TOKEN>);Note: Initialization requires passing of the application context, reference to main activity, and the provided SDK Token
The following override is necessary in your MainActivity. It is responsible for establishing the connection.
@Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { if (requestCode == VPN_PREPARED && resultCode == RESULT_OK) { actSDK.connectVPN(); } super.onActivityResult(requestCode, resultCode, data); }
Implementing the interface is required or else the SDK will throw an error. The following callback methods are for your use:
void vpnInitComplete(); // called when vpn init is complete and ready to connect void onVPNConnected(); // called when vpn state is connected void onVPNDisconnected(); // called when vpn state is disconnected void onVPNConnecting(); // called when vpn state is connecting void onVPNFailed(); // called when vpn failed void onVPNRetrying(); // called when vpn is retrying
Connect VPN
actSDK.connectVPN()
Disconnect VPN
actSDK.disconnectVPN()
Return VPN Connected State
Returns true if connected. Returns false if disconnectedactSDK.isVpnConnected()
Get regions list
Returns String array of regionsactSDK.getRegions()
Get currently set region
Returns String value of currently selected regionactSDK.getCurrentRegion()
Get the default region
Returns the value of the default region set by the SDKactSDK.getDefaultRegion()
Change Region for VPN
Accepts the new region name to set as VPN destinationactSDK.changeRegion(regionName)
Set the Admin port.
Accepts integer value for new port numberactSDK.setAdminPort(port)