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 startSmsIntent(Context context, String phoneNumber) {
    try {// www .  ja  v  a  2s.  c o m
        Uri uri = Uri.parse("sms:" + phoneNumber);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        intent.putExtra("address", phoneNumber);
        intent.setType("vnd.android-dir/mms-sms");
        context.startActivity(intent);
    } catch (Exception ex) {
        Log.e(TAG, "Error starting sms intent.", ex);
        Toast.makeText(context, "Sorry, we couldn't find any app to send an SMS!", Toast.LENGTH_SHORT).show();
    }
}

From source file:Main.java

public static Drawable GetUrlDrawable(String url) {
    try {//from   w w w.j a v  a 2  s.  c  om
        URL aryURI = new URL(url);
        URLConnection conn = aryURI.openConnection();
        InputStream is = conn.getInputStream();
        Bitmap bmp = BitmapFactory.decodeStream(is);
        return new BitmapDrawable(bmp);
    } catch (Exception e) {
        Log.e("ERROR", "urlImage2Drawable failed with image url at " + url, e);
        return null;
    }
}

From source file:Main.java

public static String getAppVersionName(Context context) {
    String versionName = "";
    try {/*from ww  w .  ja  va  2s.  c om*/
        // ---get the package info---
        PackageManager pm = context.getPackageManager();
        PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
        versionName = pi.versionName;

        if (versionName == null || versionName.length() <= 0) {
            return "";
        }
    } catch (Exception e) {
        Log.e("VersionInfo", "Exception", e);
    }
    return versionName;
}

From source file:Main.java

private static void throwError(Throwable any) {
    Log.e("AsyncUtils", "Error occurred:", any);
    throw new RuntimeException(any);
}

From source file:Main.java

public static String convertStreamToString(InputStream is) {
    if (is != null) {
        StringBuilder sb = new StringBuilder();
        String line;//from   w  w  w .j  ava  2s.c  o  m

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            while ((line = reader.readLine()) != null) {
                sb.append(line).append("\n");
            }
        } catch (IOException e) {
            Log.e(e.getClass().getName() + " convertStreamToString", e.getMessage(), e);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                Log.e(e.getClass().getName() + " convertStreamToString", e.getMessage(), e);
            }
        }
        return sb.toString();
    } else {
        return "";
    }
}

From source file:Main.java

public static String getFile(final String filename) {
    String s = "";
    final File f = new File(filename);

    if (f.exists() && f.canRead()) {
        try {/*from w w w  .  ja v  a 2 s. com*/
            final BufferedReader br = new BufferedReader(new FileReader(f), 256);
            String buffer = null;
            while ((buffer = br.readLine()) != null) {
                s += buffer + "\n";
            }

            br.close();
        } catch (final Exception e) {
            Log.e(TAG, "Error reading file: " + filename, e);
            s = null;
        }
    }
    return s;
}

From source file:Main.java

public static String getAppName(Context context) {

    String appName = "";
    try {//from   w  ww  . j  a v  a  2  s  .  com
        // ---get the package info---
        PackageManager pm = context.getPackageManager();
        PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);

        appName = pm.getApplicationLabel(pi.applicationInfo).toString();

        if (appName == null || appName.length() <= 0) {
            return "";
        }
    } catch (Exception e) {
        Log.e("VersionInfo", "Exception", e);
    }
    return appName;
}

From source file:Main.java

public static Date ConvertFromWebService(final String strDate) {

    final String[] formats = new String[] { "yyyy-MM-dd'T'HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ss.SSSXXX",
            "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd'T'HH:mm", "yyyy-MM-dd" };

    for (final String frm : formats) {
        try {//  w w w  .j av  a 2 s .  c o m
            final SimpleDateFormat format = new SimpleDateFormat(frm, Locale.US);
            format.setTimeZone(TimeZone.getTimeZone("UTC"));
            return format.parse(strDate);
        } catch (final Exception ex) {
            Log.e("IGWHelper", "Failed to convert Web Service Date.", ex);
        }
    }
    return null;
}

From source file:Main.java

public static boolean startActivityUsingScheme(Activity a, String scheme, Bundle args) {
    Uri uri = Uri.parse(scheme + "://");
    Intent intent = new Intent(Intent.ACTION_RUN, uri);
    boolean result = true;
    try {//from  www  .j a v a 2  s.  c  o  m
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (args != null)
            intent.putExtras(args);
        a.startActivity(intent);
    } catch (Exception e) {
        Log.e(a.getClass().getName(), e.getMessage(), e);
        result = false;
    }
    return result;
}

From source file:Main.java

public static String getHash(String text) {
    try {//from w  w w.j a v  a2s  .  c  o  m
        return SHA1(text);
    } catch (NoSuchAlgorithmException e) {
        Log.e(LOGTAG, "NoSuchAlgorithmException: " + e.toString(), e);

        return null; // FIXME: add other hash logic
    }
}