use of org.json.JSONException in project platform_frameworks_base by android.
the class NotificationManagerService method dumpJson.
private void dumpJson(PrintWriter pw, DumpFilter filter) {
JSONObject dump = new JSONObject();
try {
dump.put("service", "Notification Manager");
dump.put("bans", mRankingHelper.dumpBansJson(filter));
dump.put("ranking", mRankingHelper.dumpJson(filter));
dump.put("stats", mUsageStats.dumpJson(filter));
} catch (JSONException e) {
e.printStackTrace();
}
pw.println(dump);
}
use of org.json.JSONException in project platform_frameworks_base by android.
the class RankingHelper method dumpJson.
public JSONObject dumpJson(NotificationManagerService.DumpFilter filter) {
JSONObject ranking = new JSONObject();
JSONArray records = new JSONArray();
try {
ranking.put("noUid", mRestoredWithoutUids.size());
} catch (JSONException e) {
// pass
}
final int N = mRecords.size();
for (int i = 0; i < N; i++) {
final Record r = mRecords.valueAt(i);
if (filter == null || filter.matches(r.pkg)) {
JSONObject record = new JSONObject();
try {
record.put("userId", UserHandle.getUserId(r.uid));
record.put("packageName", r.pkg);
if (r.importance != DEFAULT_IMPORTANCE) {
record.put("importance", Ranking.importanceToString(r.importance));
}
if (r.priority != DEFAULT_PRIORITY) {
record.put("priority", Notification.priorityToString(r.priority));
}
if (r.visibility != DEFAULT_VISIBILITY) {
record.put("visibility", Notification.visibilityToString(r.visibility));
}
} catch (JSONException e) {
// pass
}
records.put(record);
}
}
try {
ranking.put("records", records);
} catch (JSONException e) {
// pass
}
return ranking;
}
use of org.json.JSONException in project Fast-Android-Networking by amitshekhariitbhu.
the class Rx2ApiTestActivity method createAnUserJSONObject.
public void createAnUserJSONObject(View view) {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("firstname", "Rohit");
jsonObject.put("lastname", "Kumar");
} catch (JSONException e) {
e.printStackTrace();
}
Rx2AndroidNetworking.post(ApiEndPoint.BASE_URL + ApiEndPoint.POST_CREATE_AN_USER).addJSONObjectBody(jsonObject).build().setAnalyticsListener(new AnalyticsListener() {
@Override
public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) {
Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis);
Log.d(TAG, " bytesSent : " + bytesSent);
Log.d(TAG, " bytesReceived : " + bytesReceived);
Log.d(TAG, " isFromCache : " + isFromCache);
}
}).getJSONObjectObservable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<JSONObject>() {
@Override
public void onComplete() {
Log.d(TAG, "onComplete Detail : createAnUserJSONObject completed");
}
@Override
public void onError(Throwable e) {
if (e instanceof ANError) {
ANError anError = (ANError) e;
if (anError.getErrorCode() != 0) {
// received ANError from server
// error.getErrorCode() - the ANError code from server
// error.getErrorBody() - the ANError body from server
// error.getErrorDetail() - just a ANError detail
Log.d(TAG, "onError errorCode : " + anError.getErrorCode());
Log.d(TAG, "onError errorBody : " + anError.getErrorBody());
Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail());
} else {
// error.getErrorDetail() : connectionError, parseError, requestCancelledError
Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail());
}
} else {
Log.d(TAG, "onError errorMessage : " + e.getMessage());
}
}
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(JSONObject response) {
Log.d(TAG, "onResponse object : " + response.toString());
Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
}
});
}
use of org.json.JSONException in project Fast-Android-Networking by amitshekhariitbhu.
the class RxApiTestActivity method createAnUserJSONObject.
public void createAnUserJSONObject(View view) {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("firstname", "Rohit");
jsonObject.put("lastname", "Kumar");
} catch (JSONException e) {
e.printStackTrace();
}
RxAndroidNetworking.post(ApiEndPoint.BASE_URL + ApiEndPoint.POST_CREATE_AN_USER).addJSONObjectBody(jsonObject).build().setAnalyticsListener(new AnalyticsListener() {
@Override
public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) {
Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis);
Log.d(TAG, " bytesSent : " + bytesSent);
Log.d(TAG, " bytesReceived : " + bytesReceived);
Log.d(TAG, " isFromCache : " + isFromCache);
}
}).getJSONObjectObservable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<JSONObject>() {
@Override
public void onCompleted() {
Log.d(TAG, "onComplete Detail : createAnUserJSONObject completed");
}
@Override
public void onError(Throwable e) {
if (e instanceof ANError) {
ANError anError = (ANError) e;
if (anError.getErrorCode() != 0) {
// received ANError from server
// error.getErrorCode() - the ANError code from server
// error.getErrorBody() - the ANError body from server
// error.getErrorDetail() - just a ANError detail
Log.d(TAG, "onError errorCode : " + anError.getErrorCode());
Log.d(TAG, "onError errorBody : " + anError.getErrorBody());
Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail());
} else {
// error.getErrorDetail() : connectionError, parseError, requestCancelledError
Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail());
}
} else {
Log.d(TAG, "onError errorMessage : " + e.getMessage());
}
}
@Override
public void onNext(JSONObject response) {
Log.d(TAG, "onResponse object : " + response.toString());
Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
}
});
}
use of org.json.JSONException in project Fast-Android-Networking by amitshekhariitbhu.
the class ApiTestActivity method createAnUserJSONObject.
public void createAnUserJSONObject(View view) {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("firstname", "Rohit");
jsonObject.put("lastname", "Kumar");
} catch (JSONException e) {
e.printStackTrace();
}
AndroidNetworking.post(ApiEndPoint.BASE_URL + ApiEndPoint.POST_CREATE_AN_USER).addJSONObjectBody(jsonObject).setTag(this).setPriority(Priority.LOW).build().setAnalyticsListener(new AnalyticsListener() {
@Override
public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) {
Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis);
Log.d(TAG, " bytesSent : " + bytesSent);
Log.d(TAG, " bytesReceived : " + bytesReceived);
Log.d(TAG, " isFromCache : " + isFromCache);
}
}).getAsJSONObject(new JSONObjectRequestListener() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, "onResponse object : " + response.toString());
Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
}
@Override
public void onError(ANError error) {
if (error.getErrorCode() != 0) {
// received ANError from server
// error.getErrorCode() - the ANError code from server
// error.getErrorBody() - the ANError body from server
// error.getErrorDetail() - just a ANError detail
Log.d(TAG, "onError errorCode : " + error.getErrorCode());
Log.d(TAG, "onError errorBody : " + error.getErrorBody());
Log.d(TAG, "onError errorDetail : " + error.getErrorDetail());
} else {
// error.getErrorDetail() : connectionError, parseError, requestCancelledError
Log.d(TAG, "onError errorDetail : " + error.getErrorDetail());
}
}
});
}
Aggregations