Search

Tuesday, March 15, 2011

how to get timezone change event in android

recently i was trying to implement a time zone changed event in broadcast receivers since i needed to restart some threads and process and reset timers to reflect with new timezone and after a brief search on the net and sDK documents i was able to do it so thought of share it here and as a future reference for myself below is the sample code to register broadcast recievers and also the function to catch the event

Add the values (register) in manifest file as shown below

<receiver android:name="Boottzchangereciver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
</intent-filter>

extend the class with broadcast receiver to trigger event whenever timezone changes see the below code

public class Boottzchangereciver extends BroadcastReceiver {
@Override
public void onReceive(Context c, Intent i) {
// TODO Auto-generated method stub
try{
if (Intent.ACTION_TIMEZONE_CHANGED.equals(i.getAction())) {
Intent intent = new Intent();
c.startService(intent);
}}}

the above code worked for me, if you think something needs to be added or can be done other way around give your valuable feedback here

1 comments:

Anantha said...

Thanks for the post.

Post a Comment

Other Interesting Articles



Related Article Widget by Yogith

Search Powered by Google