Example usage for android.util Log i

List of usage examples for android.util Log i

Introduction

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

Prototype

public static int i(String tag, String msg) 

Source Link

Document

Send an #INFO log message.

Usage

From source file:Main.java

public static DateTime formatDateFromStr(final String dateStr) {
    DateTime dateTime = new DateTime();
    if (!TextUtils.isEmpty(dateStr)) {
        try {//  w w w  .jav a  2s . c o  m
            dateTime = DateTime.parse(dateStr, ISODateTimeFormat.dateTimeParser());
        } catch (Exception e) {
            Log.i("Exception:", e.getMessage());
        }
    }
    return dateTime;

}

From source file:Main.java

public static File getFileFromCacheOrURL(File cacheDir, URL url) throws IOException {
    Log.i(TAG, "getFileFromCacheOrURL(): url = " + url.toExternalForm());

    String filename = url.getFile();
    int lastSlashPos = filename.lastIndexOf('/');
    String fileNameNoPath = new String(lastSlashPos == -1 ? filename : filename.substring(lastSlashPos + 1));

    File file = new File(cacheDir, fileNameNoPath);

    if (file.exists()) {
        if (file.length() > 0) {
            Log.i(TAG, "File exists in cache as: " + file.getAbsolutePath());
            return file;
        } else {/*from   w  w w  .  j a  v  a2  s  .c  o  m*/
            Log.i(TAG, "Deleting zero length file " + file.getAbsolutePath());
            file.delete();
        }
    }

    Log.i(TAG, "File " + file.getAbsolutePath() + " does not exists.");

    URLConnection ucon = url.openConnection();
    ucon.setReadTimeout(5000);
    ucon.setConnectTimeout(30000);

    InputStream is = ucon.getInputStream();
    BufferedInputStream inStream = new BufferedInputStream(is, 1024 * 5);
    FileOutputStream outStream = new FileOutputStream(file);
    byte[] buff = new byte[5 * 1024];

    // Read bytes (and store them) until there is nothing more to read(-1)
    int len;
    while ((len = inStream.read(buff)) != -1) {
        outStream.write(buff, 0, len);
    }

    // Clean up
    outStream.flush();
    outStream.close();
    inStream.close();
    return file;
}

From source file:Main.java

private static void copyAssetFolder(AssetManager am, String src, String dest) throws IOException {

    Log.i("Copy ", src);
    InputStream srcIS = null;//from  w w w  .j a  v a  2 s  . c  o m
    File destfh;

    // this is the only way we can tell if this is a file or a
    // folder - we have to open the asset, and if the open fails,
    // it's a folder...
    boolean isDir = false;
    try {
        srcIS = am.open(src);
    } catch (FileNotFoundException e) {
        isDir = true;
    }

    // either way, we'll use the dest as a File
    destfh = new File(dest);

    // and now, depending on ..
    if (isDir) {

        // If the directory doesn't yet exist, create it
        if (!destfh.exists()) {
            destfh.mkdir();
        }

        // list the assets in the directory...
        String assets[] = am.list(src);

        // and copy them all using same.
        for (String asset : assets) {
            copyAssetFolder(am, src + "/" + asset, dest + "/" + asset);
        }

    } else {
        int count, buffer_len = 2048;
        byte[] data = new byte[buffer_len];

        // copy the file from the assets subsystem to the filesystem
        FileOutputStream destOS = new FileOutputStream(destfh);

        //copy the file content in bytes
        while ((count = srcIS.read(data, 0, buffer_len)) != -1) {
            destOS.write(data, 0, count);
        }

        // and close the two files
        srcIS.close();
        destOS.close();
    }
}

From source file:Main.java

public static File createCacheDir(Context context, String dirName) {
    File preparedDir;/*from   w ww .  j a v  a  2 s  .  c o m*/
    if (android.os.Environment.MEDIA_MOUNTED.equals(android.os.Environment.getExternalStorageState())) {
        preparedDir = context.getDir(dirName /* + UUID.randomUUID().toString()*/, Context.MODE_PRIVATE);
        Log.i(TAG, "Cache dir initialized at SD card " + preparedDir.getAbsolutePath());
    } else {
        preparedDir = context.getCacheDir();
        Log.i(TAG, "Cache dir initialized at phone storage " + preparedDir.getAbsolutePath());
    }
    if (!preparedDir.exists()) {
        Log.i(TAG, "Cache dir not existed, creating");
        preparedDir.mkdirs();
    }
    return preparedDir;
}

From source file:Main.java

public static int getAppVersion(Context context) {
    try {//from   ww  w .  ja v  a  2s  .  c o  m
        PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return (pi.versionCode);
    } catch (NameNotFoundException e) {
        Log.i(TAG, "Package name not found");
    }
    return (0);
}

From source file:Main.java

public static int getApplicationIconBadgeNumber(Context context) {
    SharedPreferences prefs = getApplicationIconBadgeSettings(context);
    if (prefs == null) {
        Log.i(TAG, "Failed to retrieve application icon badge number");
        return 0;
    }/*from   www  . j av  a  2s  .  c om*/
    Log.i(TAG, "Getting application icon badge number");
    return prefs.getInt(LAST_BADGE_COUNT_TAG, 0);
}

From source file:Main.java

/**
 * Print logcat message/*from  ww w .j  ava  2  s  .  c om*/
 *
 * @param title the title of the log, this help to know where the log is from
 * @param message the message passed to be printed in logcat
 * */
public static void printLog(String title, String message) {
    if (title == null)
        title = "NO TITLE";
    if (message != null) {
        LOG_TAG = "::::" + title;
        Log.i(LOG_TAG, message);
    } else {
        LOG_TAG = "::::" + " NULL TITLE";
        Log.i(LOG_TAG, " NULL MESSAGE");
    }
}

From source file:Main.java

public static void addTaintInformationToIntent(Intent i, HashSet<String> taintCategories) {
    boolean intentHasNoExtras = i.getExtras() == null ? true : false;

    Log.i("PEP", "in addTaintInformationToIntent(Intent i, HashSet<String> taintCategories)");

    //A bit of limitation here, because we do only care about the extras
    if (!intentHasNoExtras) {
        Bundle extras = i.getExtras();/*w  w w .  ja  v  a 2  s  .  com*/

        String taintKeyName = generateKeyNameForTaintInfo(extras.keySet());

        String taintInformation = null;

        if (taintCategories.size() > 1)
            taintInformation = taintCategories.toString().substring(1, taintCategories.toString().length() - 1);
        else
            taintInformation = taintCategories.iterator().next();

        i.putExtra(taintKeyName, taintInformation);
    }
}

From source file:Main.java

public static void ZLog(String Tag, boolean Message) {
    if (BaatnaLog)
        Log.i(Tag, Message + "");
}

From source file:Main.java

public static PendingIntent scheduleLocalNotification(Context context, int slot, Long alertTime,
        String titleText, String subtitleText, String messageBodyText, String tickerText) {
    Log.i(TAG, "Scheduling local notification");
    Intent alertIntent = new Intent(getNotificationName(slot));
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, slot, alertIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    if (alarmManager != null) {
        alarmManager.set(AlarmManager.RTC_WAKEUP, alertTime, pendingIntent);
    }/*from   ww  w. j a  v a2s . co m*/
    return pendingIntent;
}