[Android] Use HttpUrlConnection instead of deprecated Apache
Geoffrey Métais
git at videolan.org
Tue Aug 18 13:54:49 CEST 2015
vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Aug 18 13:30:01 2015 +0200| [e3ce87665d4024f7e699426eb36003ec7da71ab0] | committer: Geoffrey Métais
Use HttpUrlConnection instead of deprecated Apache
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=e3ce87665d4024f7e699426eb36003ec7da71ab0
---
.../org/videolan/vlc/gui/NativeCrashActivity.java | 37 ++++++++++++--------
1 file changed, 22 insertions(+), 15 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/NativeCrashActivity.java b/vlc-android/src/org/videolan/vlc/gui/NativeCrashActivity.java
index c4fb91c..cf59c62 100644
--- a/vlc-android/src/org/videolan/vlc/gui/NativeCrashActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/NativeCrashActivity.java
@@ -10,17 +10,17 @@ import android.view.View;
import android.widget.Button;
import android.widget.TextView;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.ByteArrayEntity;
-import org.apache.http.impl.client.DefaultHttpClient;
import org.videolan.vlc.R;
import org.videolan.vlc.util.Logcat;
import org.videolan.vlc.util.Util;
+import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.zip.GZIPOutputStream;
public class NativeCrashActivity extends Activity {
@@ -63,8 +63,8 @@ public class NativeCrashActivity extends Activity {
String revision = "Revision: " + getString(R.string.build_revision);
AsyncHttpRequest asyncHttpRequest = new AsyncHttpRequest();
asyncHttpRequest.execute(Build.BRAND, Build.MANUFACTURER, Build.PRODUCT, Build.MODEL,
- Build.DEVICE, Build.VERSION.RELEASE,
- buildDate, builder, revision, mLog);
+ Build.DEVICE, Build.VERSION.RELEASE,
+ buildDate, builder, revision, mLog);
}
});
@@ -106,23 +106,30 @@ public class NativeCrashActivity extends Activity {
protected Boolean doInBackground(String... params) {
if (params[0].length() == 0)
return false;
- HttpClient httpClient = new DefaultHttpClient();
- HttpPost httpPost = new HttpPost("http://people.videolan.org/~magsoft/vlc-android_crashes/upload_crash_log.php");
-
+ HttpURLConnection urlConnection = null;
try {
+ URL url = new URL("http://people.videolan.org/~magsoft/vlc-android_crashes/upload_crash_log.php");
+ urlConnection = (HttpURLConnection) url.openConnection();
+ urlConnection.setDoOutput(true);
+ urlConnection.setRequestMethod("POST");
+ urlConnection.setDoInput(true);
+ OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
+
StringBuilder msgBuilder = new StringBuilder();
for (int i = 0; i < params.length; ++i) {
msgBuilder.append(params[i]);
msgBuilder.append("\n");
}
- httpPost.setEntity(new ByteArrayEntity(compress(msgBuilder.toString())));
- httpClient.execute(httpPost);
- } catch (ClientProtocolException e) {
+ byte[] body = compress(msgBuilder.toString());
+ urlConnection.setFixedLengthStreamingMode(body.length);
+ out.write(body);
+ } catch (MalformedURLException e) {
e.printStackTrace();
- return false;
} catch (IOException e) {
e.printStackTrace();
- return false;
+ } finally {
+ if (urlConnection != null)
+ urlConnection.disconnect();
}
return true;
}
More information about the Android
mailing list