I'd like to know whether it's possible to create a VPN interface programmatically with the new VPN APIs in Android 4.0. I've looked through http://developer.android.com/resources/samples/ToyVpn but this is about creating a complete VPN client that handles the connections etc. I only want to add a new VPN configuration and possibly remove existing ones.
There are lots of questions like this but they all seem to be pre 4.0. I understand that previously this wasn't possible, but one would think that the new VPN APIs provided such functionality. So has anyone found a way to do this, or is it still not possible? If there is a way, please point me to the right direction.
It appears that this is handled internally via the com.android.settings.vpn2.VpnDialog (and related) classes, which basically do KeyStore.getInstance().put("VPN_[VPN ID]", [encoded VpnProfile object]>) -- which then causes files with names like "/data/misc/vpn/1000_VPN_[VPN ID]" to get created (where 1000 is apparently the system process ID).
Using reflection (or one of the hacks to access the hidden / internal APIs) you can do this yourself, but because your process will not be running as the system process, the system VPN browser won't see them.
However, according to this (http://code.google.com/p/android/issues/detail?id=8915), there is at least one app that does this without a rooted phone, but the source doesn't seem to be available...so perhaps there's some way to do this that I can't figure out -- I'd definitely be interested if there is.
P.S. - Here's another similar question (though it's specifically asking about using a rooted device): Create VPN profile on Android
Yes, there is a way. Use AndroidVpnService, it helps you create VPN interface on the device, there exist methods to configure that programmatically.
Related
I have an Android device that I'm using to monitor a couple of sensors with an app that I created. What useful ways are there to update the settings in my app (while it's running at a remote location) from my computer? I'm interested in sending a message to my app to tell it to email a screenshot, change sample rate, etc. Creative workarounds are encouraged.
I've already looked into C2DM and unfortunately have no experience with setting up the required third-party application server.
[EDIT] It just occurred to me that I may have grossly over simplified what you were trying to do. If this is the case my answer probably wont be of much if any help to you. The original answer follows though.
You could use TCP sockets to set up a client/server interface between your app and a command program on your computer. Then just send a set of predefined messages/commands. Two tutorials I used for learning this are Here and Here. This wont help with the computer side of the sockets code per se although if you write the computer program in Java it should effectively be the same. This is something we are doing at my company to create a custom command interface for a product we have in development.
I want to access Android API classes outside an Android project. For example is it possible to get an object to the Context of the device connected to a machine or the running emulator?
This will allow access to a system services like PowerManager or ActivityManager outside an Android device. If not via Context object, is there any other way to access the system services for a device/avd outside Android?
No way. Distributed android API classes are merely stubs good enough to compile against them.
Even most innocent stuff is stubbed out to throw RuntimeException on invocation. If you like to know status of the system, you will have to use SDK tools. Or write app exposing android objects via some remote access technology
I very much doubt that it is possible. The distributed SDK classes do not include many parts of the internal API. See, for example, this thread. Besides, what use would there be to have a system service object like PowerManager without a system (or an emulation of one) to back it up?
It sounds like what you're trying to do is not really access things on the device, as much as remotely control the device. In this case, there are some external tools that you should look into. The tools are mainly focused on testing, and are based on instrumentation for apps. You can look at robotium and monkeyrunner, to start with, as they provide a bit of functionality that might help you accomplish what you want. Other than that, you can also do what those tools do and write an app which listens for intents from adb, performs actions based on those intents, etc..., but you'll obviously be doing a lot of communication at a high level, so this might not be the most efficient (and I'm not sure how you'd transfer much data, which would be required for real RPC, which it sounds like you want to do).
I'm trying to develop an Android App which shows the signal strength of various network operators on a map. The problem is that the only way to change the network operator is by doing it by hand.
Any ideas on how I can get this information without changing it manually? I think that there are internal/private Android classes to do this.
You will need to use one or more of Google's internal APIs to do this. They are not, by default, available to Android applications for various (usually good) reasons. The API for turning tethering on and off and configuring it, for example, is not a public API and cannot be invoked directly by third party applications.
You will need to do two things. First, download the Android source code and find the API(s) you need to list and switch carrier. You can find the Android source code, and download instructions, here.
Second, you will need to use reflection to invoke the methods on those APIs. The best approach to this, and one I used myself to play with the tethering API, is to write a proxy class. Give it all the same methods as the API you want to use, and inside each method use reflection to invoke the API method. Any other technique will either (a) not compile without adding portions of the Android source code to your classpath and then (b) will compile but blow up when you deploy.
Be aware that you're best doing this on a Nexus branded device as this has the vanilla Android code on it. My (successful) attempt to write a home screen widget to turn tethering on and off worked on a Nexus One but did not work on a Samsung Galaxy Tab P1000. The device supported tethering, but Samsung had modified that part of the OS as part of their porting effort.
I'm planning to implement a simple VOIP feature, using the new android.net.sip in Android 2.3, as an extra feature of an existing Android application. Earlier, i.e. before 2.3, I tried to do a naive solution but I could not connect the other mobile phone because of the carrier network operator's firewalls!
So, I wonder, how does this new SIP package in Gingerbread bypass those firewalls, allowing mobile phones to connect directly to each other? Or will there be problems anyway? (I scanned Googles Android documentation but could not find any information on this topic.)
Thanks in advance!
/Steve
You're making an unwarranted assumption that there's a (hidden) mechanism for bypassing/traversing firewalls. Maybe there is, but quite possibly there isn't. The overall SIP documentation looks thin; this feature may well not be ready for general use, or you may well need to implement such things outside of it (STUN, TURN, UPnP, etc).
Is there a way to programmatically set a proxy server in my Android App?
I'm writing an Android App that uses some WebViews. Is there a way to set a proxy server for all network connections in my app, i.e. all content that is shown in the WebViews should be routed through the proxy?
All other Apps on the device should not be affected by this proxy settings.
Surprisingly I don't see a mechanism listed, but maybe there is one.
Ultimately, if the webview is running in your process and implemented sensibly you can programmatically patch the existing code to route network calls through some custom code which could redirect it through a proxy (or just do whatever the proxy would), but this is very complicated low level C/assembly language programming, will require even more care to make portable across reasonable platform upgrades, and shouldn't be undertaken unless you want a very 'interesting' and educational project and you have done enough research to be sure there is no better way.
After some research I'm coming to the point that there is no (official) proxy support in Android 2.2 (and most likely also in 2.3); See this issue report with over 1000(!) comments: http://code.google.com/p/android/issues/detail?id=1273
I found some potential solutions for rooted devices, e.g. setting up some new iptables rules. I did not try any of this suggestions since I need a solution that works on any devices.
We can set the proxy in android. proxysetting 1.0 is an android app to set the proxy. Don't know further details about it. But it is clear that there is a way out.