Android Context Get getRequestQueue(Context ctx)

Here you can find the source of getRequestQueue(Context ctx)

Description

get Request Queue

Declaration

public static Object getRequestQueue(Context ctx) throws Exception 

Method Source Code

//package com.java2s;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import android.content.Context;

public class Main {
    public static Object getRequestQueue(Context ctx) throws Exception {
        Object ret = null;/* w w  w  .j a  v  a  2  s .  com*/
        Class networkClass = Class.forName("android.webkit.Network");
        if (networkClass != null) {
            Object networkObj = invokeMethod(networkClass, "getInstance",
                    new Object[] { ctx }, Context.class);
            if (networkObj != null) {
                ret = getDeclaredField(networkObj, "mRequestQueue");
            }
        }
        return ret;
    }

    private static Object invokeMethod(Object object, String methodName,
            Object[] params, Class... types) throws Exception {
        Object out = null;
        Class c = object instanceof Class ? (Class) object : object
                .getClass();
        if (types != null) {
            Method method = c.getMethod(methodName, types);
            out = method.invoke(object, params);
        } else {
            Method method = c.getMethod(methodName);
            out = method.invoke(object);
        }
        //System.out.println(object.getClass().getName() + "." + methodName + "() = "+ out);
        return out;
    }

    private static Object getDeclaredField(Object obj, String name)
            throws SecurityException, NoSuchFieldException,
            IllegalArgumentException, IllegalAccessException {
        Field f = obj.getClass().getDeclaredField(name);
        f.setAccessible(true);
        Object out = f.get(obj);
        //System.out.println(obj.getClass().getName() + "." + name + " = "+ out);
        return out;
    }
}

Related

  1. getPermissionLabel(Context context, String permission)
  2. getPreferences(Context context, String campaignUrn)
  3. getPrefs(Context context)
  4. getRealPathFromURI(Context context, Uri contentUri)
  5. getReceiverMetaData(Context context, Class receiverClass, String key)
  6. getResDimen(Context context, int resId)
  7. getResourcesPath(Context context, String url)
  8. getRevokedPerms(String packageName, Context ctx)
  9. getSavedPostsPath(Context context)