Dynamic registration broadcast receiver must have an instance
Static instances don't exist
 
Set the system time zone :
AlarmManager mAlarmManager =
(AlarmManager)getSystemService(Context.ALARM_SERVICE);
mAlarmManager.setTimeZone("GMT+08:00");
Setting the time zone needs to be done in manifest.xml Add the following permissions to :
<!--
Allow time zone setting -->
<uses-permission
android:name="android.permission.SET_TIME_ZONE"
/>
 
package com.lzh.modeify;

import java.util.Calendar;
import java.util.Timer;

import android.R.integer;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;

public class ZoneService extends Service {
    private static final String ACTION_DATE_CHANGED = Intent.ACTION_DATE_CHANGED;
    private static final String ACTION_TIME_CHANGED = Intent.ACTION_TIME_CHANGED;

private BroadcastReceiver TimerChangered = new BroadcastReceiver() {

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

Calendar c = Calendar.getInstance();// Each time field can be modified individually

//            int year = c.get(Calendar.YEAR);
//            int month = c.get(Calendar.MONTH);
//            int date = c.get(Calendar.DATE);
            int hour = c.get(Calendar.HOUR_OF_DAY);
            int minute = c.get(Calendar.MINUTE);
            int second = c.get(Calendar.SECOND);

Log.v("time", Integer.toString(hour)+Integer.toString(minute)+Integer.toString(second));
        }
    };

private BroadcastReceiver stopServiceReceiver = new BroadcastReceiver() {

public void onReceive(android.content.Context context, Intent intent) {
            ZoneService.this.stopSelf();
            ZoneService.this.unregisterReceiver(stopServiceReceiver);
        };
    };

@Override
    public void onCreate() {

super.onCreate();
        Log.i("liujun", " The background process is created ...");
        IntentFilter intentFilter = new IntentFilter("closeService");
        ZoneService.this.registerReceiver(stopServiceReceiver, intentFilter);
        // The service starts the broadcast receiver , So that the broadcast receiver can continue to execute after the program exits the day after tomorrow , Receive system time change broadcast events

ZoneService.this.registerReceiver(TimerChangered, new IntentFilter(
                Intent.ACTION_TIME_TICK));

}

@Override
    public int onStartCommand(Intent intent, int flags, int startId) {

Log.i("liujun", " Background processes ...");
        return super.onStartCommand(intent, flags, startId);

}

@Override
    public void onDestroy() {

Log.i("liujun", " The background process is destroyed ...");
        super.onDestroy();
    }

@Override
    public IBinder onBind(Intent intent) {
        // TODO Automatically generated method stubs
        return null;
    }

}

 
    MainActivity.this.sendBroadcast(new Intent("closeService"));
 
    MainActivity.this.startService(new Intent(MainActivity.this,ZoneService.class));

android More articles on modifying the system time zone

  1. android Modify the dialog style

    android Modify the dialog style One . I think the custom configuration file is troublesome ? Let's modify the system customization XML File to modify the system dialog It's the same style . If it's in XML Medium style : Let's start with the style .  stay Style.x ...

  2. Linux Next, modify the system time zone

    Use /etc/localtime File modification time zone Check the current time zone first , The following example uses UTC The world's standard time zone . Suppose you need to change to Western standard time , Pacific time . # date Thu Aug ...

  3. Centos7 Modify the system time zone timezone

    Centos7 Modify the system time zone timezone Be careful : modify Linux After the time zone of the system , Install again jvm,jvm The time zone of the system is used by default . If the system time zone is set incorrectly , install jvm after , Then change the time zone of the system , but jvm My time zone still doesn't work ...

  4. RedHat Modify the system time zone

    http://blog.itpub.net/27099995/viewspace-1370723/ Today, it is said that the server time is abnormal , It's a big time difference . I wondered , It was adjusted last week . I went to check . [root ...

  5. Reprint :Linux Check out / Modify the system time zone 、 Time

    One . View and modify Linux The time zone 1. View the current time zone command : "date -R" 2. Modify settings Linux Server time zone Method A command : "tzselect" ...

  6. ( turn )AIX Modify the time zone of the system 3 And AIX Time issues ( Daylight saving time )

    original text :http://blog.csdn.net/fuwencaho/article/details/28267283 http://www.wo81.com/tec/os/aix/2014-04-30 ...

  7. android When modifying the system, the system will not go to sleep when the screen is black

    be based on android4.4 modify , stay frameworks/base/services/java/com/android/server/power/PowerManagerService.java in , Check out Sue ...

  8. Centos7 Modify the system time zone timezone

    First step : Query server time [root@localhost ~]# timedatectl Local time: Sat 2018-03-31 01:11:46 UTC Universal time: ...

  9. Android Modify the system default density

    As you know, in Anroid N in , The system adds multiple levels of density values for users to choose . The default value of the system is ro.sf.lcd_density At the same time, the size basis of the default values of other levels is also based on the default values , And then multiply it by different proportions to get ...

Random recommendation

  1. FreeImage Compile and solve problems

    FreeImage Compile and solve problems 1. download freeImage Source package wget http://downloads.sourceforge.net/freeimage/FreeImage3170.zi ...

  2. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  3. HTML5 Drag instances back and forth

    <html> <meta charset="utf-8"> <script> // Specify the data to be dragged function tdwhat(ev,obj ...

  4. Customize View(1) Simple process and sample template

    1, Inherit View , ViewGroup, or TextView wait 2, Draw related api, canvas canvas , paint paint brush 2, Rewrite important functions ( Pay attention to the order ) onMeasure  Belong to View Of ...

  5. gulp Static resource anti cache processing

    lately , Because the alumni network project has begun to have some scale . At the beginning, we should consider the management of engineering automation for static resources . I'll talk about the front-end automation tools , You may all think of Grunt,Gulp, Or Baidu's FIS. These three have their own characteristics , You can follow your own ...

  6. crack the coding interview

    crack the coding interview answer c++ 1.1 #ifndef __Question_1_1_h__  #define __Question_1_1_h__  #i ...

  7. Docker Learning notes - Docker Remote access to

    Learning content : Configure remote access for clients and daemons Server configuration -H Options : Make the server support remote access Client side usage -H Options : Make the client access the remote server The local environment DOCKER_HOST Set the default server address for client access accurate ...

  8. Altium Designer Add a catalog file

    1 Default catalog path C:\Users\Public\Documents\Altium\AD 10.0.0.20340\Library 2 Create component schematic Library chart 2.1 newly build schlib chart 2.2 Drawing element ...

  9. C# To write COM Components

    1. Create a new class library project 2. take Class1.cs Change it to the name we want   Ask if you want to rename the class at the same time , determine 3. modify Properties Under directory AssemblyInfo.cs ComVisible Property is set to True ...

  10. C Language stack 、 Heap area

    One Local variables are stored in the stack , Release memory space after function call . #include "stdio.h"; #include "stdlib.h"; int *getNum ...