Tips

okhttp 3+ post json data

I used compile ‘com.squareup.okhttp3:okhttp:3.5.0’ private class CheckUserExist extends AsyncTask<String, String, Void> { String responseString; @Override protected void onPreExecute() { super.onPreExecute(); progressDialog = new ProgressDialog(LoginActivity.this); progressDialog.setCancelable(false); progressDialog.setMessage(“Checking….”); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.show(); } @Override protected Void doInBackground(String… str) { MediaType JSON = MediaType.parse(“application/json; charset=utf-8”); Map<String, String> params = new HashMap<String, String>(); params.put(“ContactNo”, str[0]); // params.put(“name”, “your name”); JSONObject parameter… Continue reading okhttp 3+ post json data

Tips

OKHTTP 3.0

@Override protected Void doInBackground(String… str) { String Email = str[0], password = str[1]; OkHttpClient client = new OkHttpClient(); RequestBody formBody = new FormBody.Builder() .add(“email”, Email) .add(“password”, password) .build(); Request request = new Request.Builder() .url(“http://192.168.1.102/renter/index.php/api/login&#8221;) .post(formBody) .build(); try { response = client.newCall(request).execute(); if (!response.isSuccessful()) throw new IOException(“Unexpected code ” + response); { responseString = response.body().string(); System.out.println(responseString);… Continue reading OKHTTP 3.0

Tips

Pass data one activity to other activity

Passing data one activity to another using Intent.  You can use intents, which are messages sent between activities. In a intent you can put all sort of data, String, int,float,double etc. Here,  Before going to activity2, you will store a String message this way : Intent intent = new Intent(activity2.this, activity1.class); intent.putExtra(“message”, message); startActivity(intent); Here… Continue reading Pass data one activity to other activity

Tips

JsonParser class for Json Parsing

We are using some json parser class if you are using deprecated method then Don’t use because it crashes your app. Use this class instead of previous one JSONParser.java import android.util.Log; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class JSONParser { public JSONParser() { } public String makeServiceCall(String serviceUrl)… Continue reading JsonParser class for Json Parsing

Tips

How to detect mobile screen size Programatically

You can use the DisplayMetrics to get a whole bunch of information about the screen that your app is running on. First, we create a DisplayMetrics metrics object: DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); From this, we can get the information required to size the display: int widthPixels = metrics.widthPixels; int heightPixels = metrics.heightPixels; This… Continue reading How to detect mobile screen size Programatically

Tips

Start and stop service android

When ever you want to start a service all you need is startService(new Intent(this, MainService.class)); And to Stop a service anytime just call stopService(new Intent(this, MainService.class)); Remember service needs to be declared in AndroidManifest.xml. As you said that your service is working. I’m sure you have done that. Still AndroidManifest.xml <service android:enabled=”true” android:name=”.MainService” />

Tips

Pass data using Intent android

Pass the data from Activity-1 to AndroidTabRes.. as below: At sending activity… Intent intent = new Intent(current.this, AndroidTabRestaurantDescSearchListView.class); intent.putExtra(“keyName”,”value”); startActivity(intent); At AndroidTabRes.. activity… String data = getIntent().getExtras().getString(“keyName”); Thus you can have data at receiving activity from sending activity… And in your AndroidTabRestaurantDescSearchListView class, do this: String value= getIntent().getStringExtra(“keyName”); Intent intent = new Intent(this, RatingDescriptionSearchActivity.class); intent.putExtra(“keyName”,… Continue reading Pass data using Intent android