Skip to content

Instantly share code, notes, and snippets.

View erfanegtfi's full-sized avatar

Erfan Eghterafi erfanegtfi

  • Iran
View GitHub Profile
@erfanegtfi
erfanegtfi / encode_decode.java
Created April 13, 2018 12:23
convert To Hex String
public static String convertToHexString(byte[] data) {
StringBuilder buf = new StringBuilder();
for (byte b : data) {
int halfbyte = (b >>> 4) & 15;
int two_halfs = 0;
while (true) {
char c = (halfbyte < 0 || halfbyte > 9) ? (char) ((halfbyte - 10) + 97) : (char) (halfbyte + 48);
buf.append(c);
halfbyte = b & 15;
int two_halfs2 = two_halfs + 1;
public static final String md5(String s) {
String MD5 = CommonUtils.MD5_INSTANCE;
try {
MessageDigest digest = MessageDigest.getInstance(CommonUtils.MD5_INSTANCE);
digest.update(s.getBytes());
byte[] messageDigest = digest.digest();
StringBuilder hexString = new StringBuilder();
for (byte aMessageDigest : messageDigest) {
String h = Integer.toHexString(aMessageDigest & 255);
while (h.length() < 2) {
public class MyApp extends Application {
public static boolean isAppInBackground = false;
private Activity mCurrentActivity;
public void onCreate() {
super.onCreate();
setScreenOrientation();
this.mMyApp = (MyApp) getApplicationContext();
@erfanegtfi
erfanegtfi / AndroidUtils.java
Created April 13, 2018 11:30
getAppVersionName
public static String getAppVersionName() {
try {
return MyApplication.getContext().getPackageManager().getPackageInfo(MyApplication.getContext().getPackageName(), 0).versionName;
} catch (Exception ex) {
ex.printStackTrace();
return "1";
}
}
@erfanegtfi
erfanegtfi / AndroidUtils.java
Created April 13, 2018 11:18
getAppVersionCode
public static Integer getAppVersionCode() {
try {
return Integer.valueOf(MyApplication.getContext().getPackageManager().getPackageInfo(MyApplication.getContext().getPackageName(), 0).versionCode);
} catch (Exception ex) {
ex.printStackTrace();
return Integer.valueOf(1);
}
}