Created
October 6, 2014 03:05
-
-
Save easternHong/751061344daa2a316945 to your computer and use it in GitHub Desktop.
protect Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void startSelfService() { | |
// 获得系统级别服务 | |
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); | |
Intent in = new Intent(this, this.getClass()); | |
PendingIntent pin = PendingIntent.getService(this, 0, in, | |
PendingIntent.FLAG_UPDATE_CURRENT); | |
// 返回系统开机到现在的时间差 | |
long timePeriod = SystemClock.elapsedRealtime(); | |
// ELAPSED_REALTIME =3s | |
am.setRepeating(AlarmManager.ELAPSED_REALTIME, timePeriod, 3 * 1000, | |
pin); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment