Detect implicit Intent action when the Android Operating System changes the time manually

Asked

Viewed 51 times

6

I need to detect in my application when user changes system time manually. How do I do this?

For example:

If user restarts the device I can detect this event with on my Broadcast receiver so:

if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
        Intent pushIntent = new Intent(context, Service.class);

        context.startService(pushIntent);
}

Now how do I detect time change.

1 answer

3


When the system date/time is changed a android.intent.action.TIME_SET.

To intersect it, register a receiver on Androidmanifest.xml

<receiver android:name=".TimeChangeReceiver">
    <intent-filter>
        <action android:name="android.intent.action.TIME_SET"/>
    </intent-filter>
</receiver>

and write the respective Broadcastreceiver

public class TimeChangeReceiver extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {

        //Houve uma alteração na data/hora do sistema

        }
    }    
}
  • Very good answer my friend. It is not up to you more than 41 thousand points kkkk

Browser other questions tagged

You are not signed in. Login or sign up in order to post.