Search in sources :

Example 66 with JSONException

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);
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException)

Example 67 with JSONException

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;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 68 with JSONException

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()));
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) AnalyticsListener(com.androidnetworking.interfaces.AnalyticsListener) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) ANError(com.androidnetworking.error.ANError)

Example 69 with JSONException

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()));
        }
    });
}
Also used : AnalyticsListener(com.androidnetworking.interfaces.AnalyticsListener) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) ANError(com.androidnetworking.error.ANError)

Example 70 with JSONException

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());
            }
        }
    });
}
Also used : AnalyticsListener(com.androidnetworking.interfaces.AnalyticsListener) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) ANError(com.androidnetworking.error.ANError) JSONObjectRequestListener(com.androidnetworking.interfaces.JSONObjectRequestListener)

Aggregations

JSONException (org.json.JSONException)1904 JSONObject (org.json.JSONObject)1422 JSONArray (org.json.JSONArray)638 IOException (java.io.IOException)338 ArrayList (java.util.ArrayList)211 HashMap (java.util.HashMap)145 Test (org.junit.Test)128 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)98 File (java.io.File)77 Bundle (android.os.Bundle)75 VolleyError (com.android.volley.VolleyError)67 Intent (android.content.Intent)63 DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)62 Response (com.android.volley.Response)59 URL (java.net.URL)57 Map (java.util.Map)48 TextView (android.widget.TextView)46 View (android.view.View)45 RandomString (edu.umass.cs.gnscommon.utils.RandomString)44 MalformedURLException (java.net.MalformedURLException)44