use of com.android.volley.toolbox.JsonObjectRequest in project saga-android by AnandChowdhary.
the class Updater method checkForUpdates.
public static void checkForUpdates(final Context context, boolean visibility) {
final int versionCode = getVersionCode(context);
final ProgressDialog progressDialog = new ProgressDialog(context);
String updateUrl = "https://www.dropbox.com/s/bka9o3p43oki217/saga.json?raw=1";
if (visibility) {
progressDialog.setTitle(context.getString(R.string.update));
progressDialog.setMessage(context.getString(R.string.update_checking));
progressDialog.setCancelable(true);
progressDialog.show();
}
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, updateUrl, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
int updateVersionCode = response.getInt("versionCode");
if (updateVersionCode > versionCode && versionCode != 0) {
if (progressDialog.isShowing()) {
progressDialog.cancel();
}
final String apkUrl = response.getString("apkUrl");
String changelog = response.getString("changelog");
AlertDialog dialog = new AlertDialog.Builder(context).setTitle(context.getString(R.string.new_update)).setMessage(changelog).setPositiveButton(context.getString(R.string.update_now), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
File myFile = new File(Utils.getStoragePath(context), "update.apk");
if (myFile.exists())
myFile.delete();
Uri uri = Uri.parse(apkUrl);
DownloadManager dMgr = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request dr = new DownloadManager.Request(uri);
String filename = "update.apk";
dr.setTitle(context.getString(R.string.app_name) + " " + context.getString(R.string.update));
dr.setDestinationUri(Uri.fromFile(new File(Utils.getStoragePath(context) + "/" + filename)));
// dr.setDestinationInExternalPublicDir("/Saga/", filename);
dMgr.enqueue(dr);
}
}).setNegativeButton(context.getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).setCancelable(false).create();
dialog.show();
} else {
if (progressDialog.isShowing()) {
progressDialog.cancel();
Toast.makeText(context, context.getString(R.string.no_update), Toast.LENGTH_SHORT).show();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (progressDialog.isShowing()) {
progressDialog.cancel();
Toast.makeText(context, context.getString(R.string.error_connect), Toast.LENGTH_SHORT).show();
}
}
});
request.setShouldCache(false);
VolleySingleton.getInstance(context).getRequestQueue().add(request);
}
use of com.android.volley.toolbox.JsonObjectRequest in project TaEmCasa by Dionen.
the class JsonRequestCharsetTest method specifiedCharsetJsonObject.
@Test
public void specifiedCharsetJsonObject() throws Exception {
byte[] data = jsonObjectString().getBytes(Charset.forName("ISO-8859-1"));
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=iso-8859-1");
NetworkResponse network = new NetworkResponse(data, headers);
JsonObjectRequest objectRequest = new JsonObjectRequest("", null, null, null);
Response<JSONObject> objectResponse = objectRequest.parseNetworkResponse(network);
assertNotNull(objectResponse);
assertTrue(objectResponse.isSuccess());
// don't check the text in Czech, ISO-8859-1 doesn't support some Czech characters
assertEquals(COPY_VALUE, objectResponse.result.getString(COPY_NAME));
}
use of com.android.volley.toolbox.JsonObjectRequest in project android-volley by mcxiaoke.
the class JsonRequestCharsetTest method specifiedCharsetJsonObject.
@Test
public void specifiedCharsetJsonObject() throws Exception {
byte[] data = jsonObjectString().getBytes(Charset.forName("ISO-8859-1"));
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=iso-8859-1");
NetworkResponse network = new NetworkResponse(data, headers);
JsonObjectRequest objectRequest = new JsonObjectRequest("", null, null, null);
Response<JSONObject> objectResponse = objectRequest.parseNetworkResponse(network);
assertNotNull(objectResponse);
assertTrue(objectResponse.isSuccess());
// don't check the text in Czech, ISO-8859-1 doesn't support some Czech characters
assertEquals(COPY_VALUE, objectResponse.result.getString(COPY_NAME));
}
use of com.android.volley.toolbox.JsonObjectRequest in project FastDev4Android by jiangqqlmj.
the class Fdv_JsonObjectRequest method post.
/**
* 发送POST请求, 返回JSONObject对象数据
* @param url 请求地址
* @param listener 数据返回回调接口
* @param params POST请求参数
*/
public void post(String url, final Fdv_CallBackListener<JSONObject> listener, Map<String, String> params) {
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
if (listener != null) {
listener.onSuccessResponse(response);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (listener != null) {
listener.onErrorResponse(error);
}
}
});
addRequest(jsonObjectRequest, params);
}
use of com.android.volley.toolbox.JsonObjectRequest in project FastDev4Android by jiangqqlmj.
the class Fdv_JsonObjectRequest method get.
/**
* 请求返回JSONObject对象 Get请求 无参数,或者get请求的参数直接拼接在URL上面
* @param url 请求地址
* @param listener 数据回调接口
*/
public void get(String url, final Fdv_CallBackListener<JSONObject> listener) {
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
if (listener != null) {
listener.onSuccessResponse(response);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (listener != null) {
listener.onErrorResponse(error);
}
}
});
addRequest(jsonObjectRequest);
}
Aggregations