android-networking

OKhttp PUT example

强颜欢笑 提交于 2020-05-11 04:08:48
问题 My requirement is to use PUT , send a header and a body to server which will update something in the database. I just read okHttp documentation and I was trying to use their POST example but it doesn't work for my use case (I think it might be because the server requires me to use PUT instead of POST ) . This is my method with POST : public void postRequestWithHeaderAndBody(String url, String header, String jsonBody) { MediaType JSON = MediaType.parse("application/json; charset=utf-8");

OKhttp PUT example

孤街醉人 提交于 2020-05-11 04:07:16
问题 My requirement is to use PUT , send a header and a body to server which will update something in the database. I just read okHttp documentation and I was trying to use their POST example but it doesn't work for my use case (I think it might be because the server requires me to use PUT instead of POST ) . This is my method with POST : public void postRequestWithHeaderAndBody(String url, String header, String jsonBody) { MediaType JSON = MediaType.parse("application/json; charset=utf-8");

Binding to cellular network with bindProcessToNetwork does not work

柔情痞子 提交于 2020-04-07 07:09:26
问题 I am trying to bind to a cellular network on demand (wifi is still running). I have the following code: override fun onAvailable(network: Network) { super.onAvailable(network) Toast.makeText(this@MainActivity, "CELLULAR READY", Toast.LENGTH_SHORT).show() Log.e("darran", "network info is: " +connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)) Log.e("darran", "network is metered: " +connectivityManager.isActiveNetworkMetered) Log.e("darran", "bind is tru: " +connectivityManager

Binding to cellular network with bindProcessToNetwork does not work

早过忘川 提交于 2020-04-07 07:08:26
问题 I am trying to bind to a cellular network on demand (wifi is still running). I have the following code: override fun onAvailable(network: Network) { super.onAvailable(network) Toast.makeText(this@MainActivity, "CELLULAR READY", Toast.LENGTH_SHORT).show() Log.e("darran", "network info is: " +connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)) Log.e("darran", "network is metered: " +connectivityManager.isActiveNetworkMetered) Log.e("darran", "bind is tru: " +connectivityManager

Android Studio - Fast Android Networking Library Upload File to server - error

爷,独闯天下 提交于 2020-03-27 05:40:08
问题 I am trying to Upload an image taken from Camera or Gallery to a php server. To do so I am using the library Fast-Android-Networking With my code I can see the file is writing in the server however, it is saved with 0 B , also the onProgress function is logging out the correct bytes written. Any help with This? How can I properly pass the file taken from the camera or gallery to the server using this library? private File mFileTemp; btn_update.setOnClickListener(new OnClickListener() { //

Calculate network traffic stats of app during a month

邮差的信 提交于 2020-01-24 21:56:52
问题 I want to calculate the amount of network usage/network traffic stats for my app in a month. I can use TrafficStats to provides network traffic statistics, but the statistics returned by this class reset and start from zero after every reboot. I think about storing the statistics on the storage, but I want another way. So I change to use NetworkStatsManager to calculate, but most of method required API >= 23. So how can I do it with api below 23? Thank you. 回答1: you should persist the data

Retrofit 2.x : Log Header for request and response

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-24 02:26:04
问题 I am using retrofit 2.x and i want to log the header and body of request and response . HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .addInterceptor(REWRITE_CACHE_CONTROL_INTERCEPTOR) .addNetworkInterceptor(new Interceptor() { @Override public okhttp3.Response intercept(Chain chain) throws IOException { Request request = chain.request()