android-networking

Change mobile network mode (gsm, wcdma, auto)

余生长醉 提交于 2019-11-28 07:39:59
I want to change the preferred network mode ie. gsm or wcdma or auto, programmatically, from code, on Android. Is this possible, and if so how ? Answer is NO We can open directly the settings app of mobile network settings to switch between "2G" and "allow 3G" networks.A direct switch is sadly not possible. We can develop something which will show current network and allow user short-cut from the app where they can switch network. Tulio F. It is possible, I did it. For this to work, your app must be signed with the system key or have carrier privilege. Otherwise the app will throw java.lang

How To Resolve Network Host Names From IP Address

一世执手 提交于 2019-11-28 06:53:33
问题 I am working on wifi based chat engine and I was able to retrieve the list of hosts connected to current wifi network by followin this link and now got list of devices with ip addresses but i need host name from the ip address and tried following InetAddress inetAddr; try { inetAddr = InetAddress.getByName(host.hostname); String hostname = inetAddr.getHostName(); String canonicalHostname = inetAddr.getCanonicalHostName(); holder.computerName.setText("Canonical : "+host.hostname); } catch

Ethernet Connectivity through Programmatically (Android) (Rooted Device)

主宰稳场 提交于 2019-11-28 05:58:27
I have a small issue regarding Ethernet . My three questions are: Can we programmatically Turn-On/Off Ethernet ? Can we programmatically Enable/Disable Ethernet ? Can we programmatically Connect Ethernet ? The above Questions are done with the Wifi . Like We can programmatically Turn-On/Off Wifi . We can programmatically Enable/Disable Wifi . We can programmatically Connect Wifi using WifiManager . Does android provides any EthernetManager like as WifiManager to handle Ethernet ? Or, if this doesn't seem feasible, then my original requirement is: The first thing I am going to clear is "DEVICE

How to download file/image from url to your android app

五迷三道 提交于 2019-11-28 05:43:30
问题 I need my android app to make request to url to download an image from this url so I have built this class to help me, BUT it didn't work ??? public class MyAsnyc extends AsyncTask<Void, Void, Void> { public static File file; InputStream is; protected void doInBackground() throws IOException { File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); file = new File(path, "DemoPicture.jpg"); try{ // Make sure the Pictures directory exists. path.mkdirs(); URL

Android: How to Know an IP Address is a Wifi IP Address?

こ雲淡風輕ζ 提交于 2019-11-28 05:05:32
问题 I want to know the whether IP address of an Android device is Data IP or Wifi IP. 1) Device as is connected to 3G first, now the Device will be assigned to Network IP. 2) Later Device connected to WIFI , now the Device will be assigned to WIFI IP. 3)Any Android API which will let us know an IP Address is a Wifi IP Address or Network IP?? Was Using below in 2.3.5 and things were fine, but in 4.0.3 ICS has some issues.. /** * Is the IP Address a a Wifi Ip Address. * @param ipAddr * @return

Android: What Audio Mode should be set to send receive voice between devices

岁酱吖の 提交于 2019-11-28 04:03:28
问题 I am trying to stream voice/audio (two way) between two Android devices Tablet and Mobile (over java sockets). The Tablet can play received audio(voice) clearly, but the Mobile plays received audio as noise. Then i set this audio mode in the code on tablet: audioManager.setMode(AudioManager.MODE_IN_CALL); This now results in Mobile receiving clear voice. But the tablet goes silent, it does not play the received audio (or rather its not audible). I am not sure what combination (if any) of

Why would URLConnection timeout after 6+ minutes instead of 5 seconds?

半世苍凉 提交于 2019-11-28 03:45:40
问题 I am copying this method verbatim from my application, which isn't complete yet but it does attempt to provide me with a timeout stack trace if things don't go smoothly: protected boolean isHttpAlive() { boolean isHttpOk = false; HttpURLConnection httpConnection = null; try { URL gurl = new URL("http://www.amazon.com/"); URLConnection connection = gurl.openConnection(); connection.setConnectTimeout(5 * 1000); // 5 seconds! httpConnection = (HttpURLConnection) connection; int responseCode =

UDP broadcast packets not received in sleep mode

北慕城南 提交于 2019-11-28 02:11:37
问题 My Android application periodically sends and receives UDP broadcast messages on the WiFi LAN. When the display is on, everything works fine and all messages are sent and received correctly. When the display goes to sleep the application however stops receiving UDP broadcast messages (but still sends them). Acquiring the WiFiLock (as well as a Multicast Lock) does not seem to make any difference and my wifi sleep policy is set to WIFI_SLEEP_POLICY_NEVER. This is an issue on Android 2.3.3 and

Android Volley Library: How to send an image to server?

╄→гoц情女王★ 提交于 2019-11-28 01:26:51
问题 Hy guys! I have a jpg image stored on my device and I want to sent it to server (mywebsite.com/api.php). I would like to use volley library because it is made by official android developers from google and I think they will add it to the sdk as soon as possible. Right now I am using the folowing code to send Strings to the server: postRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() { @Override public void onResponse(String response) { try { // code here

How do I get IP_ADDRESS in IPV4 format

和自甴很熟 提交于 2019-11-27 18:23:42
I am trying to get the IP address of an device i.e using WIFI or 3G connection. I am getting the ip address in IPV6 format which is not understandable. I want in IPV4 format IP address.I have done google but dint found any proper solutions. here is code which I am using to get IP address of an device public String getLocalIpAddress() { try { try { for (Enumeration<NetworkInterface> en = NetworkInterface .getNetworkInterfaces(); en.hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {