Created
October 14, 2014 12:22
-
-
Save xxnjdlys/c1c71c4b41c14d5967c5 to your computer and use it in GitHub Desktop.
log util
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.wukongtv.wkremote.client.Util; | |
import android.content.Context; | |
import android.content.pm.PackageInfo; | |
import android.content.pm.PackageManager; | |
import android.nfc.Tag; | |
import android.util.Log; | |
/** | |
* Created by sadieyu | |
* Date: 14-10-14. | |
* Time: 上午11:39 | |
* Goodluck and enjoy it. | |
*/ | |
public class HelpfulUtil { | |
private static String TAG = "SADIEYU"; | |
private static boolean DEBUG; | |
public static void setDebugMode(String tag,boolean b) { | |
DEBUG = b; | |
TAG = tag; | |
} | |
public static void logV(/*String tag, */String fmt, Object... params) { | |
if (DEBUG) { | |
Log.v(TAG, String.format(fmt + " %s ", params)); | |
} | |
} | |
public static void logI(/*String tag, */String fmt, Object... params) { | |
if (DEBUG) { | |
Log.i(TAG, String.format(fmt + " %s ", params)); | |
} | |
} | |
public static void logE(/*String tag, */String fmt, Object... params) { | |
if (DEBUG) { | |
Log.e(TAG, String.format(fmt + " %s ", params)); | |
} | |
} | |
public static void logD(/*String tag, */String fmt, Object... params) { | |
if (DEBUG) { | |
Log.d(TAG, String.format(fmt + " %s ", params)); | |
} | |
} | |
public static int getAppVersionCode(Context c) { | |
PackageInfo pkgInfo; | |
int versionCode = 0; | |
try { | |
pkgInfo = c.getPackageManager().getPackageInfo(c.getPackageName(), 0); | |
versionCode = pkgInfo.versionCode; | |
} catch (PackageManager.NameNotFoundException e) { | |
e.printStackTrace(); | |
} | |
return versionCode; | |
} | |
public static String getAppVersionName(Context c) { | |
PackageInfo pkgInfo; | |
String versionName = null; | |
try { | |
pkgInfo = c.getPackageManager().getPackageInfo(c.getPackageName(), 0); | |
versionName = pkgInfo.versionName; | |
} catch (PackageManager.NameNotFoundException e) { | |
e.printStackTrace(); | |
} | |
return versionName; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment