2

I have created an application that changes the date/time settings on Android, but if I test it, it doesn't work.

Is that because of security from system inside android, or is something wrong?

Here is my code:

if (killed) {
    // TODO Auto-generated method stub
    AlarmManager a = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    long current_time_milliens = System.currentTimeMillis();
try {
    a.setTime((long) current_time_milliens - 86400);
} catch (Exception e) {
    // add exception handling
}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Amoniks
  • 21
  • 2
  • Looks like it's not possible. Read this answer: http://stackoverflow.com/a/11708781/2065418 – Damien R. Oct 21 '13 at 08:50
  • "it don't works" provides us with no information. Does your real code catch and swallow exceptions like that? If so, that's the first thing to change - an exception may well be thrown with really useful information, and you've no idea... – Jon Skeet Oct 21 '13 at 08:50
  • It don't works yes, is there something wrong with that ? I just post my code and said that it's not possible to change date / time with it... and i wanted to know if this was normal because android system is locked that possibility ? – Amoniks Oct 21 '13 at 08:54
  • @Amoniks 1st change ur system time. after u will get app time – Karthikeyan Karthik Oct 21 '13 at 08:59

2 Answers2

1

You cannot change this unless it is a system app (protection level signatureOrSystem) or your phone is rooted (since there is a protection in the linux layer). This means that if it is a regular Play app, it is not possible. Also, if you would succeed in having the above requirements, your app also needs the permission android.permission.SET_TIME.

The only way to change time from a non-system app is to let the user set it manually:

startActivity(new Intent(android.provider.Settings.ACTION_DATE_SETTINGS));
dorien
  • 5,265
  • 10
  • 57
  • 116
0

David Wasser has answered a similar question;
"It is not possible for an application to change the date or time on an (non-rooted) Android device.

From the documentation for AlarmManager.setTime():

Requires the permission android.permission.SET_TIME.

See http://developer.android.com/reference/android/app/AlarmManager.html"

Original Comment:
getting method not found setTime(long) in AlarmManager when tried to set time and date in android system time

Community
  • 1
  • 1
Devrim
  • 15,345
  • 4
  • 66
  • 74