Reputation: 2040
I wanted to change timezone in android programmatically like to set timezone as "America/Los_Angeles". How can I do this. How can this be possible by using id's.
Upvotes: 15
Views: 31768
Reputation: 1
You should have system signatures for setting timezones. if you are not manifacturer for your device may be you can contact them and ask for keystore files. after that you can sign your app as system with keystore file.
Upvotes: -1
Reputation: 39018
In your AndroidManifest.xml
<uses-permission android:name="android.permission.SET_TIME_ZONE"/>
In your source:
AlarmManager am = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
am.setTimeZone("America/Los_Angeles");
Upvotes: 23
Reputation: 8792
If this is on a simulator or a device that you have root on, you could run
adb shell "su -c 'setprop persist.sys.timezone America/Los_Angeles; stop; sleep 5; start'"
Upvotes: 6
Reputation: 1214
Abhishek's code simply defines a Calendar instance with a specific format to be used in the app, so that will not work.
It is not possible to change the phone's timezone programmatically. You could redirect the user to the appropriate settings, however:
startActivity(new Intent(android.provider.Settings.ACTION_DATE_SETTINGS));
Upvotes: 8