Is there a way to pass my PCs/Laptops current local IP to my App via command line argument or something else?
I don't want to switch to a static IP or enter it all the time I begin to work on my App that relies on a local server that runs on my laptop. I think the easiest way would be to pass it as a macro from the run configurations. Is there a way to do this or something similar?
There are two main ways to do this.
Write your IP Address to a system property and then read that in your app.
Start your activity with an intent that contains the IP Address as an extra.
Of the two, I'd suggest using an intent. Refer to this other answer for how to use adb to start your app. In your activity code, in onCreate you should call getIntent and then get your extra and parse it.
Related
I do some automated tasks an android over adb commands, at one part i need to access a webview inside the app and control it. Until now i did these things:
I get the running webview processes with this command adb shell cat /proc/net/unix
For each process i do a protforwarding with this command adb forward tcp:9222 localabstract:webview_devtools_remote_25866
I do a get request to http://localhost:9222/json and get an array with webvies accessible over this proccess (so i clould check the title and the attaced state to find the right one)
My problem is now that since a few days I always get an empty array. I still able to see the webvies at chrome://inspect/#devices and can connect.
Does anyone have an idea why i only get an empty array or know an alternative solution?
In the meantime I have found the problem. The app I control no longer uses a webview but a browser popup, so it can't be found via the search with webview.
I am trying to create a web service for my android application. The web service is supposed to run on UltiDev, the issue i get is when i try to access the web service through a local android emulator. I was advised to change the url of the web service to http://10.0.2.2:portnumber/serviceName but when i attempt to make this change i get an error in UltiDev. It turns out that i have to bind the port first before i can do this, however UltiDev does not allow me to do this. This is the error i get. Sorry i can't post the actual image because i need reputation points first.
Failed to register application because System.ApplicationException: Unable to register application because not all required applications settings are specified: Listen endpoints are either not specified or are already taken by other applications.
at UWS.Configuration.WebAppConfigEntry.ApplyFinalDefaultsAndValidateBeforeSaving()
.....
Could you please clarify whether you are trying to do this programmatically, or using UWS Explorer UI? Please attach a screenshot - it always helps.
In case you use UWS Explorer, the screenshot below shows how to add a port binding. If you click "Specify host name or IP address" radiobutton, you will be able to specify an IP address.
If you do all that, but then you still get the same error, it means your system acts as if all IP+ports are already taken, which often is caused by security software, like firewall+antiviruses.
I am try to set custom DNS suffix (yahoo.com in my case) using adb command
setprop net.dns.search yahoo.com
I verified it using
getprop net.dns.search
and it returns yahoo.com
However, when I type music in my browser and run tcpdump in the adb, here is what I get.
So, the query is actually "music.yahoo.com", but somehow, the android default browser says page not found
Why is it not going to music.yahoo.com when the actual query is that?
When I set the suffix to google.com and enter finance in my browser. It just opens google.com and not finance.google.com
Do anyone have any idea of what could be wrong? Any help is much appreciated!!
You are confusing something maybe. net.dns.search adds suffix to searched host names. You pass music, it will append yahoo.com. Ok, you got music.yahoo.com in DNS, but programs thinks it is music.
In HTTP, you specify which host you connect to. And there will be Host: music. Not music.yahoo.com. Server receives music and don't know for which virtual server it should be. Thus it uses default site as fallback.
Is there reason you want it to behave this way? It is intended to save your own time by setting your local domain. But it will not work well on public internet.
I am trying to code an addon in XBMC linux environment within Android.
I can see Mac address inside XBMC. But I'd like to grab the mac address for the addon and I can't figure out how.
mac=uuid.getnode()
I have already tried with code like above but gives me numbers only and different everytime when run in android.
could someone give any suggestion please
You can use XBMC InfoLabels
if xbmc.getInfoLabel('Network.MacAddress') != None:
mac_address = xbmc.getInfoLabel('Network.MacAddress')
else:
mac_address = None
If you look at the docs:
Get the hardware address as a 48-bit positive integer. The first time this runs, it may launch a separate program, which could be quite slow. If all attempts to obtain the hardware address fail, we choose a random 48-bit number with its eighth bit set to 1 as recommended in RFC 4122.
The first part explains why it's "numbers only". It's supposed to be a number. If you want that in some particular hex-string format, just format it—e.g., by calling hex().
The last sentence explains why it's "different everytime". If you look at the source, on any non-Windows platform, getnode will try _unixdll_getnode, then _ifconfig_getnode, then fall back to a random number. The former requires a function called uuid_generate_time in either libuuid or libc, which doesn't exist on Android. The latter runs the command ifconfig with a series of different flags and searches for specific strings, and falls back to arp and lanscan. Again, none of this works on Android.
There is no recommended way to get the MAC address on Android, mainly because they don't want you to get one. This blog post explains why, and this SO question (especially Seka Alekseyev's answer) adds more detail. Some apps try persisting the MAC address once they've gotten it, and never checking again, which gets around some of the problems, but not most of them.
There is a Java API to get the MAC for each service where it makes sense—WiFi, 3G, Bluetooth, etc. It's up to you to decide which is "the" MAC, and you need the right permissions (e.g., android.permission.ACCESS_WIFI_STATE), and there may be no value or a garbage value, but you can get it with code like this:
WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);
String mac = wm.getConnectionInfo().getMacAddress();
As far as I know, there's nothing in SL4A or any other Android Python distribution that exposes these functions directly, so you'll have to write your own wrapper.
You can get mac address on this easy way, assume "eth0" is your network device name:
o = open('/sys/class/net/eth0/address', 'r')
mac_address = o.read().strip() #on "ff:ff:ff:ff:ff:ff" form
I'm trying to set up a web server using the Restlet framework on my Android phone. My idea is to build a game where one phone creates some markers on a map which then can be transferred directly to other phones using rest. At first (and for simplicity) I want to transfer a List of Objects.
Running a server on my computer seems to work fine, but when I transfer the code to my Android application, it won't start the server. Here is the code:
Component serverComponent = new Component();
serverComponent.getServers().add(Protocol.HTTP, 80);
final Router router = new Router(serverComponent.getContext().createChildContext());
router.attach("/gamedata", GameDataResourceServer.class);
serverComponent.getDefaultHost().attach(router);
serverComponent.start();
When the line serverComponent.start(); is executed, this Exception is thrown:
java.net.BindException: Permission denied (maybe missing INTERNET permission), although the internet permission is in the manifest file. Searching for some tutorials didn't help either. The result are either client applications or very complicated scenarios.
Could someone give an example for a simple application?
In Unix-type environments you typically need root access to bind to a TCP port below 1024. You're trying to bind to port 80, and unless you run this code as root the OS will prevent the request.