android-networking

Usage of consumeContent() of HttpEntity

隐身守侯 提交于 2019-12-02 04:03:00
What is the purpose of consumeContent() of class or org.apache.http.HttpEntity in Android? When should one use it ane can it have side effects? I'm trying to fix a bug in an app which makes requests to a server using HttpClient and sometimes if one particular request fails it will subsequently fail despite the fact that internet is OK. The app calls this method at the end of input stream read. As @Sotirios suggested, HttpEntity.consumeContent() is deprecated so please use EntityUtils.consume(HttpEntity) when feasible. Let's then broadly talk about consuming an HttpEntity . Consuming an

Can GeoCoder getFromLocation method cause a NetworkOnMainThreadException to be thrown?

喜夏-厌秋 提交于 2019-12-02 02:35:10
I have an app which was tested thoroughly and working fine on Android Gingerbread (and older Android versions). I've noticed from users' reported crash errors that phones running later versions of the Android operating system are throwing a NetworkOnMainThreadException . I'm trying to work through my code and eliminate/fix all culprits. Would the GeoCoder getFromLocation and getFromLocationName methods throw a NetworkOnMainThreadException if called from the main/ui thread? Seems like these Geocoder methods and any networking or i/o calls are going to throw up a NetworkOnMainThreadException .

Is it possible to separate WebView's UI and HTTP threads?

旧街凉风 提交于 2019-12-01 15:17:19
For various reasons, I need to runOnUiThread() the actual instantiation & initialization of WebView . Which means that its underlying HTTP connections are also made on the UI thread? If this is true, is it possible to separate the WebView's UI thead from the HTTP connections thread? If it is possible, what is the proper way of accomplishing this? Nate I find it very hard to believe that Android would run remote HTTP requests on the UI thread, assuming you initiate the requests via WebView.loadUrl() . This would make for a terrible user experience. Just quickly, I ran an Android app in the

Android P2P service discovery callbacks not being called

荒凉一梦 提交于 2019-12-01 11:14:43
I'm fairly new to Android and I'm working on an application that will exchange data over WIFI direct and I would like to use DNS Service Discovery instead of pure P2P discovery to get more useful information like device "nick names" etc. So far I've followed the tutorials at http://developer.android.com/training/connect-devices-wirelessly/index.html and read through the documentation. My application seems to register it's local service successfully and the onSuccess callback from discoverServices is always called, however the txtServiceRecord from other devices (I'm using 2 devices) is never

how to upload the image into server

女生的网名这么多〃 提交于 2019-12-01 08:05:53
问题 i tried to upload the image to the server for two days but i could not post the image .the coding is compiled and run sucessfully but the imag is not write into the server. this is my coding: import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL;

Android P2P service discovery callbacks not being called

六月ゝ 毕业季﹏ 提交于 2019-12-01 07:28:16
问题 I'm fairly new to Android and I'm working on an application that will exchange data over WIFI direct and I would like to use DNS Service Discovery instead of pure P2P discovery to get more useful information like device "nick names" etc. So far I've followed the tutorials at http://developer.android.com/training/connect-devices-wirelessly/index.html and read through the documentation. My application seems to register it's local service successfully and the onSuccess callback from

Get Wifi Interface name on Android

别说谁变了你拦得住时间么 提交于 2019-11-30 23:47:15
I am currently developing a sort of wifi sniffer. To achieve that I use a tcpdump binary compiled for arm. But it's assume that I know the name of the Wifi Interface. According to the SDK documentation NetworkInterface provide a getName() method. I plan to use this method, so the first step is to get the NetworkInterface objet corresponding to my wifi interface. To do that I use the WifiInfo to get the ip adress, then get an InetAddress corresponding to this IP and finally get an instance of NetworkInterface by using the static method getByInetAddress(InetAddress address). Here is my code :

Android UnknownHostException Facebook SDK

落爺英雄遲暮 提交于 2019-11-30 20:54:25
Here is the situation. My app runs fine, and is able to establish connections with URLs. BUT after a few hours of leaving the app running, all of a sudden the Facebook requests are giving me the following error. 09-26 10:01:25.175: W/System.err(252): java.net.UnknownHostException: Host is unresolved: xyz.com:80 09-26 10:01:25.175: W/System.err(252): at java.net.Socket.connect(Socket.java:1037) 09-26 10:01:25.175: W/System.err(252): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:62) 09-26 10:01:25.175: W/System.err(252): at org.apache.harmony

How to upload a bitmap image to server using android volley library?

↘锁芯ラ 提交于 2019-11-30 15:53:19
How to upload a bitmap image to server using android volley library ?I am trying to use android volley to upload images to server . If there is no such option in android volley ,can you please suggest me the best way to make networking actions faster. You are welcome to message me the links to any available tutorials online pertaining to this subject FrancescoAzzola As far as I know, Volley isn't the right choice to send a large amount of data (like an image) to a remote server. Anyway, if you want to send an image you should extend Request class and implements your logic. You could take as an

Using an Android Service to handle a network connection

こ雲淡風輕ζ 提交于 2019-11-30 15:29:16
I'm working on an Android app that needs to maintain a network connection to a chat server. I understand that I can create a service to initiate the connection to the server, but how would the service notify an Android Activity of new incoming messages? The Activity would need to update the view to show the new messages. I'm pretty new to Android, so any help is appreciated. Thanks! Jordan Can you pass a handler to your service? First, define your handler as an interface. This is an example, so yours may be more complex. public interface ServerResponseHandler { public void success(Message[]