Example usage for android.util Log e

List of usage examples for android.util Log e

Introduction

In this page you can find the example usage for android.util Log e.

Prototype

public static int e(String tag, String msg) 

Source Link

Document

Send an #ERROR log message.

Usage

From source file:Main.java

public static void LOGE(final String tag, String message) {
    Log.e(tag, message);
}

From source file:Main.java

public static void printHashKey(Context context) {
    try {//  w ww.  j a  v a 2  s.  co m
        PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(),
                PackageManager.GET_SIGNATURES);
        for (android.content.pm.Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.e("HASH KEY:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (PackageManager.NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }
}

From source file:Main.java

public static void takeScreenshot(String fileName, String directory, int quality, Instrumentation inst) {
    Method takeScreenshot;//from w  ww  .  ja va 2  s  .  com
    Method getUiAutomation;
    Object mUiAutomationVaule;
    Bitmap bitmap = null;
    if (android.os.Build.VERSION.SDK_INT < 18) {
        Log.e(TAG, "Build.VERSION is :" + android.os.Build.VERSION.SDK_INT + ", it should >= API 18");
        return;
    }
    try {
        getUiAutomation = Instrumentation.class.getDeclaredMethod("getUiAutomation");
        mUiAutomationVaule = getUiAutomation.invoke(inst, new Object[] {});
        takeScreenshot = mUiAutomationVaule.getClass().getDeclaredMethod("takeScreenshot", new Class[] {});
        if (mUiAutomationVaule != null)
            bitmap = (Bitmap) takeScreenshot.invoke(mUiAutomationVaule, new Object[] {});
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(directory + File.separator + fileName);
        if (fileName.endsWith(".png")) {
            bitmap.compress(Bitmap.CompressFormat.PNG, quality, fos);
        } else if (fileName.endsWith(".jpg")) {
            bitmap.compress(Bitmap.CompressFormat.JPEG, quality, fos);
        }
        fos.flush();
        fos.close();
    } catch (Exception e) {
        Log.e(TAG,
                "Can't save the screenshot! Requires write permission (android.permission.WRITE_EXTERNAL_STORAGE) in AndroidManifest.xml of the application under test.");
        e.printStackTrace();
    }
}

From source file:Main.java

public static void stopCounter(String tag) {
    long stopTime = System.currentTimeMillis();
    if (listTimes.containsKey(tag)) {
        long startTime = listTimes.get(tag);
        long elapsedTime = stopTime - startTime;
        NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
        System.out.println("#" + tag + "# {End counting :" + numberFormat.format(elapsedTime) + " ms }");
        listTimes.remove(tag);//from  www  .ja  v a2  s.c  o m
    } else
        Log.e(tag, "NO KEY IN HASHMAP To calculate Time");

}

From source file:Main.java

public static String readInStream(InputStream in) {
    try {//  www . j  a v  a2s .c  o m
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] buffer = new byte[512];
        int length = -1;
        while ((length = in.read(buffer)) != -1) {
            out.write(buffer, 0, length);
        }
        out.close();
        in.close();
    } catch (IOException e) {
        Log.e("FileTest", e.getMessage());
    }
    return null;
}

From source file:Main.java

public static Bitmap getEmotion(Context context, String key) {
    String fileName = "default_emotions_package/" + MAP.get(key);
    try {/*from w  ww. j a  va  2s.  c om*/
        AssetManager am = context.getAssets();
        return BitmapFactory.decodeStream(am.open(fileName));
    } catch (IOException e) {
        Log.e(TAG, e.getMessage());
    }
    return null;
}

From source file:Main.java

/**
 * Unbind drawables./*  w  w  w  . ja v a2  s.c o m*/
 *
 * @param view the view
 */
public static void unbindDrawables(View view) {
    if (view == null)
        return;
    if (view.getBackground() != null) {
        view.getBackground().setCallback(null);
    }
    if (view instanceof ViewGroup) {
        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
            unbindDrawables(((ViewGroup) view).getChildAt(i));
        }
        try {
            ((ViewGroup) view).removeAllViews();
        } catch (UnsupportedOperationException mayHappen) {
            Log.e("Error:", mayHappen.getMessage());
        }
    }
}

From source file:Main.java

public static void logGlobalException(Context c, String[] logs) {
    String dir = c.getExternalFilesDir(null).getParent();
    try {/*w w w  .  j  a va  2 s.c om*/
        File file = new File(dir + "/error_logs.log");
        // if file doesnt exists, then create it
        if (!file.exists()) {
            file.createNewFile();
        }
        FileOutputStream fos = new FileOutputStream(file, true);

        for (String log : logs) {
            fos.write((log + "\n\n").getBytes());
        }
        fos.close();
    } catch (IOException ioe) {
        Log.e("AndroidUtils", "An exception has occured in logGlobalException!");
        ioe.printStackTrace();
    }
}

From source file:Main.java

public static void goToMiuiPermissionActivity_V7(Context context) {
    Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR");
    intent.setClassName("com.miui.securitycenter",
            "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
    intent.putExtra("extra_pkgname", context.getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (isIntentAvailable(intent, context)) {
        context.startActivity(intent);//from ww  w .j  a  va  2 s  .  co m
    } else {
        Log.e(TAG, "Intent is not available!");
    }
}

From source file:Main.java

public static void goToMiuiPermissionActivity_V6(Context context) {
    Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR");
    intent.setClassName("com.miui.securitycenter",
            "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
    intent.putExtra("extra_pkgname", context.getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (isIntentAvailable(intent, context)) {
        context.startActivity(intent);/*w ww  .ja v  a  2  s .  c o m*/
    } else {
        Log.e(TAG, "Intent is not available!");
    }
}