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, Throwable tr) 

Source Link

Document

Send a #ERROR log message and log the exception.

Usage

From source file:Main.java

public static void startDialer(Context context, String phoneNumber) {
    try {//from www .  jav  a2 s. com
        Intent dial = new Intent();
        dial.setAction(Intent.ACTION_DIAL);
        dial.setData(Uri.parse("tel:" + phoneNumber));
        context.startActivity(dial);
    } catch (Exception ex) {
        Log.e(TAG, "Error starting phone dialer intent.", ex);
        Toast.makeText(context, "Sorry, we couldn't find any app to place a phone call!", Toast.LENGTH_SHORT)
                .show();
    }
}

From source file:Main.java

public static String getAppVersion(Context context) {
    String versionName = "";
    try {/*from  w w w. j  a  v  a  2 s. c o  m*/
        // ---get the package info---
        PackageManager pm = context.getPackageManager();
        PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
        versionName = pi.versionName;

    } catch (Exception e) {
        Log.e("VersionInfo", "Exception", e);
    }
    return versionName;
}

From source file:Main.java

public static boolean writeOneLine(String fname, String value) {
    if (!new File(fname).exists()) {
        return false;
    }/*from  w w w .  jav a2  s.c  o  m*/
    try {
        FileWriter fw = new FileWriter(fname);
        try {
            fw.write(value);
        } finally {
            fw.close();
        }
    } catch (IOException e) {
        String Error = "Error writing to " + fname + ". Exception: ";
        Log.e("TAG", Error, e);
        return false;
    }
    return true;
}

From source file:Main.java

public static void writeObject(String root, String filename, Object object) {
    File file = new File(root, filename);
    try {/*from w w w.  java 2 s . co m*/
        FileOutputStream fos = new FileOutputStream(file);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(object);
        oos.flush();
        oos.close();
    } catch (Exception e) {
        Log.e(TAG, String.format("Failed to write [%s]", file), e);
    }
}

From source file:Main.java

public static byte[] serializeObject(Object o) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    try {//from w  w  w.  j  a v  a2 s. co  m
        ObjectOutput out = new ObjectOutputStream(bos);
        out.writeObject(o);
        out.close();

        byte[] buf = bos.toByteArray();

        return buf;
    } catch (IOException ioe) {
        Log.e("serializeObject", "error", ioe);

        return null;
    }
}

From source file:Main.java

/**
 * Get the SD card directory./* w w w .  j  a  v  a2  s  .co  m*/
 *
 * @return The SD card directory.
 */
@NonNull
public static String getSdCardPath() {
    String sdCardDirectory = Environment.getExternalStorageDirectory().getAbsolutePath();

    try {
        sdCardDirectory = new File(sdCardDirectory).getCanonicalPath();
    } catch (IOException ioe) {
        Log.e("Uri", "Could not get SD directory", ioe);
    }
    return sdCardDirectory;
}

From source file:Main.java

public static void copyStream(InputStream is, OutputStream os) {
    try {/*from w  ww. j  av a2s .  c  o  m*/
        final byte[] bytes = new byte[BUFFER_SIZE];

        int count = is.read(bytes, 0, BUFFER_SIZE);
        while (count > -1) {
            os.write(bytes, 0, count);
            count = is.read(bytes, 0, BUFFER_SIZE);
        }

        os.flush();
    } catch (Exception ex) {
        Log.e("", "", ex);
    }
}

From source file:Main.java

/**
 * Get current version number./*  w ww. jav a 2 s .  c  o  m*/
 * 
 * @return
 */
public static String getVersionNumber(Context context) {
    String version = "?";
    try {
        PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        version = pi.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Package name not found", e);
    }
    ;
    return version;
}

From source file:Main.java

public static String getResourceString(String recourceName, Activity context) {
    Class rStringClass = null;//www  .  j a va 2s  .c  o m
    try {
        if (rStringClass == null) {
            rStringClass = Class.forName(
                    new StringBuilder().append(context.getPackageName()).append(".R$string").toString());
        }
        return context.getResources()
                .getString(((Integer) rStringClass.getDeclaredField(recourceName).get(null)).intValue());
    } catch (Exception e) {
        Log.e(context.getPackageName(), e.getMessage(), e);
        context.finish();
    }
    return "";
}

From source file:Main.java

public static String getSystemProperty(String propName) {
    String line;//from w  ww .jav a 2  s  .  com
    BufferedReader input = null;
    try {
        Process p = Runtime.getRuntime().exec("getprop " + propName);
        input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
        line = input.readLine();
        input.close();
    } catch (IOException ex) {
        Log.e(TAG, "Unable to read sysprop " + propName, ex);
        return null;
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                Log.e(TAG, "Exception while closing InputStream", e);
            }
        }
    }
    return line;
}