My Andoird app needs to register a token of the device in order to have push notifications. Up to now, I have always used this code:
final HttpClient httpclient = new DefaultHttpClient();
final HttpPost httppost = new HttpPost("http://mysite/registration.php");
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Log.e("token:", token);
Log.e("android_id:", android_id );
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("token", token));
nameValuePairs.add(new BasicNameValuePair("device", android_id));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); /***/
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost); /***/
String responseBody = EntityUtils.toString(response.getEntity()); /***/
Anyway, Android Studio keeps on telling this code is deprecated and I wish I was not forced to add Apache dependencies. For example, I don't want to have
dependencies {
compile group: 'org.apache.httpcomponents' ,
name: 'httpclient-android' ,
version: '4.3.5.1'
}
in my build.gradle.
So, how can I update my code? In particular, I'm having difficulties in understand how to update the lines with /***/. Thank you for your attention