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

static public void CopyAsset(Context ctx, File path, String filename) throws IOException {
    AssetManager assetManager = ctx.getAssets();
    InputStream in = null;/*w w w  . ja  v  a2s. c  om*/
    OutputStream out = null;

    // Copy files from asset folder to application folder
    try {
        in = assetManager.open(filename);
        out = new FileOutputStream(path.toString() + "/" + filename);
        copyFile(in, out);
    } catch (IOException e) {
        Log.e(TAG, e.getMessage());
        throw e;
    } finally {
        // Reclaim resources
        if (in != null) {
            in.close();
            in = null;
        }
        if (out != null) {
            out.flush();
            out.close();
            out = null;
        }
    }
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    try {//w ww . ja va  2s .c  o  m
        //define object of ConnectivityManager
        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);

        //define object of NetworkInfo and get detailed info about
        // the currently active default data network from ConnectivityManager
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();

        //check connection
        return activeNetworkInfo != null && activeNetworkInfo.isConnected();
    } catch (Exception ex) {
        Log.e("Helper", "isNetworkAvailable: " + ex.getMessage());
        return false;
    }
}

From source file:Main.java

private static boolean setProxyPreICS(WebView webView, String host, final int port) {
    HttpHost proxyServer;//from w  w w .  j  a v a  2  s  .co  m
    if (null == host) {
        proxyServer = null;
    } else {
        proxyServer = new HttpHost(host, port);
    }
    Class networkClass = null;
    Object network = null;
    try {
        networkClass = Class.forName("android.webkit.Network");
        if (networkClass == null) {
            Log.e(LOG_TAG, "failed to get class for android.webkit.Network");
            return false;
        }
        Method getInstanceMethod = networkClass.getMethod("getInstance", Context.class);
        if (getInstanceMethod == null) {
            Log.e(LOG_TAG, "failed to get getInstance method");
        }
        network = getInstanceMethod.invoke(networkClass, new Object[] { webView.getContext() });
    } catch (Exception ex) {
        Log.e(LOG_TAG, "error getting network: " + ex);
        return false;
    }
    if (network == null) {
        Log.e(LOG_TAG, "error getting network: network is null");
        return false;
    }
    Object requestQueue = null;
    try {
        Field requestQueueField = networkClass.getDeclaredField("mRequestQueue");
        requestQueue = getFieldValueSafely(requestQueueField, network);
    } catch (Exception ex) {
        Log.e(LOG_TAG, "error getting field value");
        return false;
    }
    if (requestQueue == null) {
        Log.e(LOG_TAG, "Request queue is null");
        return false;
    }
    Field proxyHostField = null;
    try {
        Class requestQueueClass = Class.forName("android.net.http.RequestQueue");
        proxyHostField = requestQueueClass.getDeclaredField("mProxyHost");
    } catch (Exception ex) {
        Log.e(LOG_TAG, "error getting proxy host field");
        return false;
    }

    boolean temp = proxyHostField.isAccessible();
    try {
        proxyHostField.setAccessible(true);
        proxyHostField.set(requestQueue, proxyServer);
    } catch (Exception ex) {
        Log.e(LOG_TAG, "error setting proxy host");
    } finally {
        proxyHostField.setAccessible(temp);
    }
    Log.d(LOG_TAG, "Setting proxy with <= 3.2 API successful!");
    return true;
}

From source file:Main.java

public static String getDownloadDir() {
    String status = Environment.getExternalStorageState();
    if (status == null || !status.equals(Environment.MEDIA_MOUNTED)) {
        return null;
    }//from  www.  j  a  v a 2s.  c  om

    String path = null;

    // get the sdcard directory
    File sdFile = Environment.getExternalStorageDirectory();
    if (null != sdFile) {
        path = sdFile.toString();
    } else {
        path = "/sdcard/";
    }

    path += "/download";

    File destDir = new File(path);
    if (!destDir.exists()) {
        try {
            if (!destDir.mkdirs()) {
                Log.e("getDownloadDir", "create folder " + path + " failed");
                return null;
            }
        } catch (SecurityException e) {
            Log.e("getDownloadDir", "create folder " + path + " failed: " + e.toString());
            return null;
        }
    }

    return path;
}

From source file:Main.java

public static void applyPermission(Context context) {
    Intent intent = new Intent();
    intent.setClassName("com.android.settings", "com.android.settings.Settings$OverlaySettingsActivity");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (isIntentAvailable(intent, context)) {
        context.startActivity(intent);//  ww w  .ja  v  a  2 s  .  c o m
    } else {
        intent.setClassName("com.qihoo360.mobilesafe", "com.qihoo360.mobilesafe.ui.index.AppEnterActivity");
        if (isIntentAvailable(intent, context)) {
            context.startActivity(intent);
        } else {
            Log.e(TAG, "can't open permission page with particular name, please use "
                    + "\"adb shell dumpsys activity\" command and tell me the name of the float window permission page");
        }
    }
}

From source file:Main.java

public static String getIpAddress() {
    try {/*from   ww  w . ja  v a 2 s  .  co  m*/
        for (Enumeration<?> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
            NetworkInterface intf = (NetworkInterface) en.nextElement();
            for (Enumeration<?> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                InetAddress inetAddress = (InetAddress) enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress()) {

                    return inetAddress.getHostAddress().toString();
                }
            }
        }
    } catch (SocketException ex) {
        Log.e("system", ex.toString());
    }
    return null;
}

From source file:Main.java

public static void printE(String tag, Exception e) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    e.printStackTrace(pw);/*  w w  w  . j  a v a2  s .  co m*/
    Log.e(tag, sw.toString());
}

From source file:Main.java

public static Document StringToxml(String resultData) {

    StringReader sr = new StringReader(resultData);
    InputSource is = new InputSource(sr);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = null;
    Document doc = null;/*  w w  w  . j  av a 2  s.  co  m*/
    try {
        builder = factory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {

        Log.e(DEBUG_TAG, "the StringToxml method ParserConfigurationException erro ");
    }
    try {
        doc = builder.parse(is);

    } catch (SAXException e) {

        Log.e(DEBUG_TAG, "the StringToxml method SAXException erro ");

    } catch (IOException e) {
        Log.e(DEBUG_TAG, "the StringToxml method IOException erro ");
    }
    return doc;
}

From source file:Main.java

public static String MD5(String md5) {
    if (md5 == null) {
        return null;
    }//from   w w w. java2s  .c om
    try {
        java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
        byte[] array = md.digest(md5.getBytes());
        StringBuilder sb = new StringBuilder();
        for (byte anArray : array) {
            sb.append(Integer.toHexString((anArray & 0xFF) | 0x100).substring(1, 3));
        }
        return sb.toString();
    } catch (java.security.NoSuchAlgorithmException e) {
        Log.e("tmessages", e.getMessage());
    }
    return null;
}

From source file:Main.java

/**
 * initialize method, called inside the Chart.init() method.
 *
 * @param context//w  ww.  jav a 2s.  co m
 */
@SuppressWarnings("deprecation")
public static void init(Context context) {

    if (context == null) {
        // noinspection deprecation
        mMinimumFlingVelocity = ViewConfiguration.getMinimumFlingVelocity();
        // noinspection deprecation
        mMaximumFlingVelocity = ViewConfiguration.getMaximumFlingVelocity();

        Log.e("MPChartLib-Utils", "Utils.init(...) PROVIDED CONTEXT OBJECT IS NULL");

    } else {
        ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
        mMinimumFlingVelocity = viewConfiguration.getScaledMinimumFlingVelocity();
        mMaximumFlingVelocity = viewConfiguration.getScaledMaximumFlingVelocity();

        Resources res = context.getResources();
        mMetrics = res.getDisplayMetrics();
    }
}