android-networking

How do I explicitly disable chunked streaming mode for HTTP connections in Android?

一笑奈何 提交于 2019-11-30 14:53:38
问题 I'm targeting a REST web service from Android 4.0 using HttpsURLConnection . This works fine unless I try to POST something. This is the relevant code section: connection.setDoOutput(true); connection.setChunkedStreamingMode(0); ByteArrayOutputStream out = new ByteArrayOutputStream(); serializeObjectToStream(out, object); byte[] array = out.toByteArray(); connection.getOutputStream().write(array, 0, array.length); This throws the following exception: java.net.HttpRetryException: Cannot retry

Square's Retrofit response parsing logic: streaming?

走远了吗. 提交于 2019-11-30 14:21:03
Could you please explain Square's Retrofit response parsing logic. I'm interested in case when we should receive & parse a big json (>100Kb) - will Retrofit wait while all content will be received from server and only than parse it, or it will start to parse it immediately while getting stream data? My goal is to speedup response processing. Are there any options about it available to configure? As soon as the HTTP client parses the headers, the InputStream will be handed back to Retrofit which will then hand it directly to the Converter . This means that as the underlying converter mechanism

How do I explicitly disable chunked streaming mode for HTTP connections in Android?

雨燕双飞 提交于 2019-11-30 12:00:39
I'm targeting a REST web service from Android 4.0 using HttpsURLConnection . This works fine unless I try to POST something. This is the relevant code section: connection.setDoOutput(true); connection.setChunkedStreamingMode(0); ByteArrayOutputStream out = new ByteArrayOutputStream(); serializeObjectToStream(out, object); byte[] array = out.toByteArray(); connection.getOutputStream().write(array, 0, array.length); This throws the following exception: java.net.HttpRetryException: Cannot retry streamed HTTP body From debugging I realized that the output stream I get via connection.getOuputStream

Why does multicast reception not work on some Android devices?

五迷三道 提交于 2019-11-30 09:10:56
It seems multicast reception does not work on some Android devices. I can not receive multicast with 4 out of 13 test devices. On those 4 devices it seems the app does not send the IGMP request to join the multicast group. The code to receive the multicast looks like so: WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); WifiManager.WifiLock wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, TAG); WifiManager.MulticastLock multicastLock = wifiManager.createMulticastLock(TAG); multicastLock.setReferenceCounted(true); wifiLock.acquire(

Android Broadcast Address

空扰寡人 提交于 2019-11-30 08:31:36
问题 I am making a Client Server application for my Android phone. I have created a UDP Server in Python which sits and listens for connections. I can put either the server IP address in directly like 192.169.0.100 and it sends data fine. I can also put in 192.168.0.255 and it find the server on 192.169.0.100 . Is it possible to get the broadcast address of the network my Android phone is connected to? I am only ever going to use this application on my Wifi network or other Wifi networks. Cheers

Changing Android hotspot settings

心已入冬 提交于 2019-11-30 05:28:33
With the release of API level 26, my app's core functionality broke, this being, changing the users' hotspot setting within the application. To get and set this configuration I am using the following functions from the WifiManager hidden api: getWifiApConfiguration and setWifiApConfiguration . Method getWifiApConfiguration = wifiManager.getClass().getMethod("getWifiApConfiguration"); getWifiApConfiguration.invoke(wifiManager); This is working with devices prior to Android O, but in this version I get the following error: App not allowed to read or update stored WiFi Ap config (uid = 10168) The

How to check Wifi is connected, but no Internet access in Android

冷暖自知 提交于 2019-11-30 04:59:17
I would like to know why wifi is connected but there is no internet access in Android. How can i check it? My code is: ConnectivityManager cn=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo nf=cn.getActiveNetworkInfo(); if(nf != null && nf.isConnected() ) { Flag2=false; Log.e("network--------", "1--------------"); if (cn.getActiveNetworkInfo().isConnectedOrConnecting()) {Log.e("network--------", "11111111111111--------------"); } else {Log.e("network--------", "2222222222222--------------"); } } else { Log.e("network--------", "2--------------"); } You could

Using an Android Service to handle a network connection

拈花ヽ惹草 提交于 2019-11-29 22:30:40
问题 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! 回答1: Can you pass a handler to your service? First, define your handler as an interface. This is an example, so

Volley framewok request keeps objects in memory

感情迁移 提交于 2019-11-29 18:11:08
I'm making a volley request in this way: public void makeRequest(BaseRequest request, Response.Listener<JSONObject> responseListener, Response.ErrorListener errorListener) { if (Constants.DEBUG) Log.i(TAG, "Sending: " + request.getUrlRequest()); JsonObjectRequest jsObjRequest = new JsonObjectRequest(METHOD, request.getUrlRequest(), null, responseListener, errorListener); // disable cache jsObjRequest.setShouldCache(false); jsObjRequest.setTag(mTag); mQueue.add(jsObjRequest); } mTag is a Class type. I have an activity where on its onCreate method I call the volley request with this:

Check internet connection in android (not network connection)

旧街凉风 提交于 2019-11-29 16:03:03
I have a problem with checking internet connection in android at runtime. I use some different methods to check internet connection but i don't know which one is better . because each of them have some problems . Method 1 check internet connection by pinging Google : Runtime runtime = Runtime.getRuntime(); try { Process mIpAddressProcess = runtime.exec("/system/bin/ping -c 1 8.8.8.8"); int mExitValue = mIpAddressProcess.waitFor(); return mExitValue == 0; } catch (InterruptedException | IOException ignore) { ignore.printStackTrace(); } Method 2 check internet connection by ConnectivityManager :