VPN Connection for Android Studio Apps - android

I'm hoping to write an app in Android Studio which will require me to connect to a VPN.
I've read through the documentation on this, but I'm having trouble understanding some things about it, which the source code provided at the bottom of the article hasn't completely clarified to me.
Will this VpnService mean that I don't need to develop a separate VPN app for my main app to use for a VPN connection?
When the app opens for the very first time, I'll need to present a page for the user to enter the VPN details (IP address etc.) However, after these settings have been saved, how do I then open the VPN connection on app startup?

Answering your points.
You don't need to develop a separate app for VPN. You can use the vpn service class for creating vpn connections.
Just take the input from the user and pass them when configuring the vpn connection. Save the values in shared preferences and load from it for the next time use.

Related

How to connect Android Studio & ESP WROOM 02 (ESP8266)?

First time post here, I am new to programming with android studio. I am not sure if I came to the right place to ask for help. I am not sure what I am trying to do is possible or where to search for tutorials on the subject. I don't have experience with connecting devices over WiFi at all.
Here is what I am trying to do:
I have an App I created with Android Studio, this app has a list of "devices", these devices will control a window over a wifi connection.
In the app, I simply have an "Open" button and a "Close" button for each "device".
I need to be able to show that the 'device' (which is the wifi stepper below) is connected to my app.
I am using the ESP-WROOM-02 (ESP8266) wifi module. Specifically, this wifi-stepper: https://www.crowdsupply.com/good-robotics/wi-fi-stepper
I can give more info or code samples of my project if needed, and any help is much appreciated. I don't know how or where to start.
tldr; I am unsure how to program the connection between the app and the module so that when I press open, the window will open.
Update, As now you say they are both on the same network and the device says "HTTP(S) JSON RESTful interface" you app just needs to make https requests to the ip address of the device.
Docs https://bitbucket.org/aklofas/wifistepper/src/master/documentation/src/interfaces/restful.md
And in Android one method of http requests https://developer.android.com/reference/java/net/HttpURLConnection.html
The device has fairly good documentation of how to set it all up and talk to it via it's various interfaces.

How to make only traffic from some APPs go through VPN in Android?

I want to build a VPN APP on Android basing VPN service. one special requirement of this VPN APP is it has a white list, only traffic come from APPs in this list will go to VPN server. All rest traffic go to what they used to go.
For example, I have a VPN server in USA, and I am in China. I want Facebook goes through VPN. but Youku goes to Youku's server directly.
My first problem here is how can determine some traffic come from which APP?
I know it's possible, because there an APP called no root firewall can block traffic per APP, which is also basing Android VPN service.
https://play.google.com/store/apps/details?id=app.greyshirts.firewall
I'm new to Android, can anybody tell me how to do this?
Thanks in advance!
Have a look at the addAllowedApplication() method, it accepts the packageName who's traffic should be allowed to go through VpnService.

android - Force my app to use WiFi only

I'm a PHP developer, but I'm now finishing Android App that different developer started.
One of the requirements is to make it possible to disallow mobile connection. For that I already created checkbox preference on settings page I got.
But I can't find correct way to globaly disallow my app to use mobile connection for data transactions. I don't need to disable connection, I just need to forbid my app to use it and use only WiFi. I got too much places, where connection is done and no time to refactor it.
TL;DR
I need to globally forbid my app to use mobile connection without disabling connection itself.
Just can say one thing is that Android allows to turn on/off WiFi manually only because of security.

How to turn on Android VPN tunnel from source code?

I have implemented an Android application which connects to its application server via a VPN tunnel. Thats fine.
However I want that the application turn on the Android VPN service itself ,rather than I am turning on the VPN on Android manually.
Is it possible to turn on this from java source code, like
// TO DO
if (something) {
VPN ON
}
Currently it's not possible to do that. Event with the latest classes in Android 4.0, User action is required to create a VPN connection. It's considered a security issue to be able progrmmatically to establish vpn connection (e.g. without the user to notice).
It is not possible to turn off the VPN from Java source code, unless the device is rooted, then there some hacks around. (so I have been told being an Android developer for a major software company) It is almost possible to do but it will take writing something in Native Code. There are some companies that are currently attempting to do this in an SDK. Authentec is one, but even in there SDK it is not possible to shut off the VPN connection yet. I came here looking to see if anyone has done this before but I know it is not possible through Java code, it will have to be in Native Code ( C for simpletons like myself)

Programmatically start / launch VPN connection

I am developing Enterprise applications that need to connect to
servers behind the firewall. Can my app start VPN connection
programmatically?
On 2.0+ platforms, VPN is supported by the platform. Assuming user
has already setup VPN parameters, can my app start the VPN
connection? Suppose user has not setup any VPN parameters, can my app
supply those parameters? and start VPN connection?
We're facing this problem at our shop. For now our best shot is trying to use Android internal API to connect to the VPN the same way that the system preferences app does.
First, you need to set up an environment that allows you to access internal API: http://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-1-introduction/
Then we can implement something like this http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/4.4.4_r1/com/android/settings/vpn2/VpnSettings.java#258
I don't know if we will have any permission issues with this, but IMHO this is the best option we have right now
EDIT: this need root privileges in order to avoid java.lang.SecurityException: Unauthorized Caller errors.
Suppose user has not setup any VPN parameters, can my app supply those parameters? and start VPN connection?
yes, I think it's possible with VpnService class as in this example
Assuming user has already setup VPN parameters, can my app start the VPN connection?
I'm looking for it also. I'm not sure, but I think maybe it can be done with android.net.vpn. See this
AnyConnect by Cisco has private API: http://www.cisco.com/c/en/us/td/docs/security/vpn_client/anyconnect/anyconnect30/administration/guide/anyconnectadmin30/acmobiledevices.html#71308
Yes you can start a VPN connection.what version of android are you using? this link should be useful . give details for better understanding.

Categories

Resources