Example usage for android.content.pm PackageManager getClass

List of usage examples for android.content.pm PackageManager getClass

Introduction

In this page you can find the example usage for android.content.pm PackageManager getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:Main.java

public static String[] getRevokedPerms(String packageName, Context ctx) {
    String[] revokedPerms = null;
    PackageManager pkgManager = ctx.getPackageManager();
    Method getRevokedPermissions;
    try {//w w  w .  j  a va2 s  .  co m
        getRevokedPermissions = pkgManager.getClass().getMethod("getRevokedPermissions",
                java.lang.String.class);
        Object[] params = new Object[] { packageName };
        revokedPerms = (String[]) getRevokedPermissions.invoke(pkgManager, params);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return revokedPerms;
}

From source file:Main.java

public static void setRevokedPermissions(String packageName, String[] permissions, Context ctx) {
    PackageManager pkgManager = ctx.getPackageManager();
    Method setRevokedPermissions;

    try {//from  w  ww  . j  av  a 2  s  .c o m
        setRevokedPermissions = pkgManager.getClass().getMethod("setRevokedPermissions", java.lang.String.class,
                String[].class);
        Object[] params = new Object[] { packageName, permissions };
        setRevokedPermissions.invoke(pkgManager, params);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:enterprayz.megatools.Tools.java

static public boolean hasTelephony(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm == null)
        return false;

    PackageManager pm = context.getPackageManager();

    if (pm == null)
        return false;

    boolean retval = false;
    try {/*ww  w .jav  a 2  s  .  c  o m*/
        Class<?>[] parameters = new Class[1];
        parameters[0] = String.class;
        Method method = pm.getClass().getMethod("hasSystemFeature", parameters);
        Object[] parm = new Object[1];
        parm[0] = "android.hardware.telephony";
        Object retValue = method.invoke(pm, parm);
        if (retValue instanceof Boolean)
            retval = ((Boolean) retValue).booleanValue();
        else
            retval = false;
    } catch (Exception e) {
        retval = false;
    }

    return retval;
}