2010년 12월 25일 토요일

MySQL에서 Null 처리

ifnull(컬럼명, 대체값)

2010년 12월 2일 목요일

bada에서 md5 hash 구하기

const char* DhrUtils::GetMd5N(const char* str)
{
Md5Hash md5;
ByteBuffer* byteText = new ByteBuffer();
byteText->Construct(strlen(str) + 1);
byteText->SetArray((byte*)str, 0, strlen(str));
byteText->SetByte(strlen(str), '\0');
byteText->Flip();
AppLog("position %d, limit %d, capacity %d", byteText->GetPosition(), byteText->GetLimit(), byteText->GetCapacity());
ByteBuffer* byteMd5Text = md5.GetHashN(*byteText);
const byte* pActualOutput = byteMd5Text->GetPointer();

String id;
id.Format(33, L"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
pActualOutput[0], pActualOutput[1], pActualOutput[2], pActualOutput[3],
pActualOutput[4], pActualOutput[5], pActualOutput[6], pActualOutput[7],
pActualOutput[8], pActualOutput[9], pActualOutput[10], pActualOutput[11],
pActualOutput[12], pActualOutput[13], pActualOutput[14], pActualOutput[15]);

char* ret = new char[33];
memset(ret, '\0', 33);
AppLog("MD5: %ls", id.GetPointer());
snprintf(ret, 33, "%ls", id.GetPointer());

delete byteMd5Text;
delete byteText;

return ret;
}

Android에서 Home 으로 보내기

Intent intent = new Intent();
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.HOME");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

Android에서 sd카드 마운트 상태 확인하기

public static boolean isSdMounted() {
return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
}

Android에서 sqlite 버전 구하기

public static String getSqliteVersion() {
Cursor cursor = SQLiteDatabase.openOrCreateDatabase(":memory:", null).rawQuery("select sqlite_version() AS sqlite_version", null);
String sqliteVersion = "";
while(cursor.moveToNext()){
sqliteVersion += cursor.getString(0);
}
cursor.close();
return sqliteVersion;
}

Android에서 deviceId 구하기

public static String getDeviceId(Context context) {
TelephonyManager telManager = (TelephonyManager)context.getSystemService(
Context.TELEPHONY_SERVICE);

return telManager.getDeviceId();
}

필요 Permission
android.permission.READ_PHONE_STATE

Android에서 md5 hash 구하기

public static String getMd5(String s) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] messageDigest = md.digest(s.getBytes());
BigInteger number = new BigInteger(1, messageDigest);
String md5 = number.toString(16);
while (md5.length() < 32)
md5 = "0" + md5;
return md5;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}