android-networking

Uploading High res images in android

不羁的心 提交于 2019-12-22 09:24:03
问题 Hi I wanted to upload high res images to my php server.Right now i am sending images to my server using encoded string.Problem here is i can not upload high res image it leads me to Out of memory. My image is around 1-2 Mb large in size. Here is a snippet how i upload image to server. String encodedPagerpath=""; if(!FILE_PAGER_PATH.equals("") && FILE_PAGER_PATH.length()!=0) { byte [] b=imageTobyteArray(FILE_PAGER_PATH,150,150); if(b!=null) { encodedPagerpath=Base64.encodeToString(b, Base64

how to use retrofit 2 to send file and other params together

无人久伴 提交于 2019-12-21 20:17:24
问题 I am looking for an example how could I send file and other params together to server. I have to send server JSON which { "title": "title", "file": "uploaded file instance", "location": { "lat": 48.8583, "lng": 2.29232, "place": "Eiffel Tower" } } How could I create Retrofit to handle this case? If file is a string I know how to handle this. If file is File object I have no idea how to do this. 回答1: Use gson and create a model class for the location. Add the following dependencies to your

Simulate Slow Internet Connection on a REAL device? [duplicate]

送分小仙女□ 提交于 2019-12-21 03:53:25
问题 This question already has answers here : Simulate low bandwidth in android (11 answers) Closed 5 years ago . I need to test my application in conditions where even 2G Internet connectivity isn't at its full coverage (i.e. 2 bars instead of 4, 2G). I prefer conducting these tests over WiFi. Is there a way (programmatically or otherwise) to tell the Android OS on the real device to slow down or throttle Internet connection 56 Kbit/s? Note: I know how to do this on the emulator. I'm looking for

How to find wifi and network data usage separately by particular application in android?

妖精的绣舞 提交于 2019-12-20 12:08:38
问题 recived = TrafficStats.getUidRxBytes(uid); send = TrafficStats.getUidTxBytes(uid); TrafficStats.getMobileRxBytes(); TrafficStats.getMobileTxBytes(); TrafficStats.getTotalRxBytes(); TrafficStats.getTotalTxBytes(); i have application id and i can get that application data usage but i cant get information in more detailed like data usage using wifi and network. i want to find both separately for all installed application in device. how can i find that.? i have already tried many things but didn

How to use a self signed SSL certificate in Android

寵の児 提交于 2019-12-20 10:55:50
问题 This thing has been bugging me for couple days now. I've read lots of other questions about this whole issue and still haven't been able to proceed. I've created a simple test application just to test SSL on Android. The application has only one button and when clicked the application tries to send "Hello World" over SSL encrypted connection to my test server, which then responds with the exact same phrase. First I created a test key and test certificate for my server using openssl. Then I've

Square`s OkHttp. Download progress

孤街醉人 提交于 2019-12-20 08:40:36
问题 Is there any way to get downloading file progress when using square`s OkHttp? I did not find any solution in Recipes. They have class Call which can get content asynchronically, but there is no method to get current progress. 回答1: Oops answer was obvious. Sorry for dumb question. Just need to read InputStream as usual. private class AsyncDownloader extends AsyncTask<Void, Long, Boolean> { private final String URL = "file_url"; @Override protected Boolean doInBackground(Void... params) {

Android failing to connect to MySQL database properly

♀尐吖头ヾ 提交于 2019-12-20 06:16:57
问题 I'm trying to get the basics of an Android app that sends and receives data from a MySQL server (my implementation will have nothing to do with this learning example). Here's the code so far: package com.davekelley.polling; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.ParseException;

Can GeoCoder getFromLocation method cause a NetworkOnMainThreadException to be thrown?

半世苍凉 提交于 2019-12-20 03:00:12
问题 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? 回答1: Seems like

Android koush/ion lib unable to post and receive JSON response

假装没事ソ 提交于 2019-12-20 01:57:12
问题 I am using ION to GET/POST for REST and also to get Images into ListView but I am unable to use POST method and receive response as a JSON The ION version that I am using is 1.3.7. Tested on emulator and also on real devices 4.1.1, 4.2.2 and 4.4 ION Link on gitHub This code is called on a button click to post to the server after the validations are successful. This is inside support fragment v4:20 defined in gradle compile 'com.android.support:support-v4:20.+' /////////////////// Ion.with

Get Wifi Interface name on Android

巧了我就是萌 提交于 2019-12-19 04:02:02
问题 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