Skip to content

Instantly share code, notes, and snippets.

@paulononaka
Created March 18, 2011 15:20
Show Gist options
  • Save paulononaka/876246 to your computer and use it in GitHub Desktop.
Save paulononaka/876246 to your computer and use it in GitHub Desktop.
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
Copy link
Author

This requires that you use the same certificate of system in your application or you must embed your application in the Android compilation. In both alternatives, put a attribute in AndroidManifest.xml -> android:sharedUserId="android.uid.system"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment