Skip to content

Instantly share code, notes, and snippets.

View paulononaka's full-sized avatar

Paulo Henrique Nonaka paulononaka

  • Belo Horizonte, MG - Brazil
View GitHub Profile
@paulononaka
paulononaka / AndroidGetSystemProp.java
Created March 23, 2011 19:33
A better way to get a system property.
public static String getSystemProp(String key) throws Exception {
Class<?> c = Class.forName("android.os.SystemProperties");
Class<?>[] types = new Class[] {String.class};
Method method = c.getMethod("get", types);
return (String) method.invoke(null, new Object[] {key});
}
@paulononaka
paulononaka / AndroidSettingDateTime.java
Created March 18, 2011 15:20
Setting a specific date/time in Android.
private void settingDeviceDateTime(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
SystemClock.setCurrentTimeMillis(c.getTimeInMillis());
Log.d(TAG, "Setting time to: " + new SimpleDateFormat("MM/dd/yyyy hh:mm:ss").format(c.getTime()));
}
@paulononaka
paulononaka / AndroidGetPropSystem.java
Created March 18, 2011 14:51
Getting a system property in Android
public static String getPropSystem(String key) throws IOException {
BufferedReader bis = null;
try {
Process ifc = Runtime.getRuntime().exec("getprop " + key);
bis = new BufferedReader(new InputStreamReader(ifc.getInputStream()));
return bis.readLine();
} finally {
bis.close();
}
}