5

I need to set device time dynamically.if it possible please guide me

So far as I tried

MainActivity.java

Calendar c = Calendar.getInstance();    
c.set(2010, 1, 1, 12, 00, 00);

manifest.xml

<permission android:name="android.permission.SET_TIME"
    android:protectionLevel="signatureOrSystem"
    android:label="@string/app_name" />

Thanks in advance

SilentKiller
  • 6,944
  • 6
  • 40
  • 75
Android_coder
  • 9,953
  • 3
  • 17
  • 23

1 Answers1

2
//set Time to device
    Calendar c = Calendar.getInstance();
    c.set(2013, 8, 15, 12, 34, 56);
    AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    am.setTime(c.getTimeInMillis());

//   and set in Manifest.xml
 <!-- Allows applications to set the system time -->
    <permission android:name="android.permission.SET_TIME"
        android:protectionLevel="signature|system"
      />

and follow this link for more help How to set mobile system time and date in android? I think it may help u

Community
  • 1
  • 1
Spry Techies
  • 896
  • 6
  • 21