├── app ├── .gitignore ├── libs │ └── ddpush-1.0.02.jar ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ └── layout │ │ │ │ └── activity_main.xml │ │ ├── aidl │ │ │ └── service │ │ │ │ └── keppliveservice │ │ │ │ └── StrongService.aidl │ │ ├── java │ │ │ └── service │ │ │ │ └── keppliveservice │ │ │ │ ├── StrongService.aidl │ │ │ │ ├── Params.java │ │ │ │ ├── receiver │ │ │ │ ├── BootAlarmReceiver.java │ │ │ │ ├── TickAlarmReceiver.java │ │ │ │ └── KeepLiveReceivers.java │ │ │ │ ├── DateTimeUtil.java │ │ │ │ ├── service │ │ │ │ ├── MyJobService.java │ │ │ │ ├── KeepLiveService.java │ │ │ │ └── OnLineService.java │ │ │ │ ├── Util.java │ │ │ │ ├── KeepLiveUtils.java │ │ │ │ └── MainActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── service │ │ │ └── keppliveservice │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── service │ │ └── keppliveservice │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── README.md ├── .idea ├── copyright │ └── profiles_settings.xml ├── modules.xml ├── runConfigurations.xml ├── gradle.xml ├── compiler.xml └── misc.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /app/libs/ddpush-1.0.02.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ahuanghaifeng/MessagePush/HEAD/app/libs/ddpush-1.0.02.jar -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MessagePush 2 | android消息推送,服务保活研究 3 | 详细介绍地址http://blog.csdn.net/u013692888/article/details/77914181 4 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | keppLiveService 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ahuanghaifeng/MessagePush/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ahuanghaifeng/MessagePush/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ahuanghaifeng/MessagePush/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ahuanghaifeng/MessagePush/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ahuanghaifeng/MessagePush/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ahuanghaifeng/MessagePush/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ahuanghaifeng/MessagePush/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ahuanghaifeng/MessagePush/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ahuanghaifeng/MessagePush/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ahuanghaifeng/MessagePush/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ahuanghaifeng/MessagePush/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Aug 24 14:20:37 CST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/aidl/service/keppliveservice/StrongService.aidl: -------------------------------------------------------------------------------- 1 | // StrongService.aidl 2 | package service.keppliveservice; 3 | 4 | // Declare any non-default types here with import statements 5 | 6 | interface StrongService { 7 | /** 8 | * Demonstrates some basic types that you can use as parameters 9 | * and return values in AIDL. 10 | */ 11 | void StartService(); 12 | void stopService(); 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/service/keppliveservice/StrongService.aidl: -------------------------------------------------------------------------------- 1 | // StrongService.aidl 2 | package service.keppliveservice; 3 | 4 | // Declare any non-default types here with import statements 5 | 6 | interface StrongService { 7 | /** 8 | * Demonstrates some basic types that you can use as parameters 9 | * and return values in AIDL. 10 | */ 11 | void StartService(); 12 | void stopService(); 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/service/keppliveservice/Params.java: -------------------------------------------------------------------------------- 1 | package service.keppliveservice; 2 | 3 | public class Params { 4 | public static String DEFAULT_PRE_NAME = "defaultAccount"; 5 | public static String SERVER_IP = "serverIp"; 6 | public static String SERVER_PORT = "serverPort"; 7 | public static String PUSH_PORT = "pushPort"; 8 | public static String USER_NAME = "userName"; 9 | public static String SENT_PKGS = "sentPkgs"; 10 | public static String RECEIVE_PKGS = "receivePkgs"; 11 | } 12 | -------------------------------------------------------------------------------- /app/src/test/java/service/keppliveservice/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package service.keppliveservice; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/java/service/keppliveservice/receiver/BootAlarmReceiver.java: -------------------------------------------------------------------------------- 1 | package service.keppliveservice.receiver; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.util.Log; 7 | 8 | import service.keppliveservice.service.OnLineService; 9 | 10 | 11 | public class BootAlarmReceiver extends BroadcastReceiver { 12 | 13 | public BootAlarmReceiver() { 14 | 15 | } 16 | 17 | @Override 18 | public void onReceive(Context context, Intent intent) { 19 | Log.e("91ysdk", "开机广播"); 20 | Intent startSrv = new Intent(context, OnLineService.class); 21 | startSrv.putExtra("CMD", "TICK"); 22 | context.startService(startSrv); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/service/keppliveservice/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package service.keppliveservice; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("service.keppliveservice", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/service/keppliveservice/receiver/TickAlarmReceiver.java: -------------------------------------------------------------------------------- 1 | package service.keppliveservice.receiver; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.os.PowerManager.WakeLock; 7 | import android.util.Log; 8 | 9 | import service.keppliveservice.KeepLiveUtils; 10 | import service.keppliveservice.service.OnLineService; 11 | 12 | 13 | public class TickAlarmReceiver extends BroadcastReceiver { 14 | 15 | WakeLock wakeLock; 16 | 17 | public TickAlarmReceiver() { 18 | 19 | } 20 | 21 | @Override 22 | public void onReceive(Context context, Intent intent) { 23 | Log.e("91ysdk", "收到闹钟广播"); 24 | if(KeepLiveUtils.hasNetwork(context) == false){ 25 | return; 26 | } 27 | Intent startSrv = new Intent(context, OnLineService.class); 28 | startSrv.putExtra("CMD", "TICK"); 29 | context.startService(startSrv); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Android\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion '23.0.3' 6 | defaultConfig { 7 | applicationId "service.keppliveservice" 8 | minSdkVersion 15 9 | targetSdkVersion 23 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | sourceSets { main { res.srcDirs = ['src/main/res', 'src/main/res/layout'] } } 21 | } 22 | 23 | dependencies { 24 | compile fileTree(include: ['*.jar'], dir: 'libs') 25 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 26 | exclude group: 'com.android.support', module: 'support-annotations' 27 | }) 28 | testCompile 'junit:junit:4.12' 29 | compile files('libs/ddpush-1.0.02.jar') 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/service/keppliveservice/receiver/KeepLiveReceivers.java: -------------------------------------------------------------------------------- 1 | package service.keppliveservice.receiver; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.util.Log; 7 | 8 | import service.keppliveservice.KeepLiveUtils; 9 | import service.keppliveservice.service.OnLineService; 10 | 11 | /** 12 | * 网络连接改变锁屏广播和解锁 13 | * Created by haifeng on 2017/8/28. 14 | */ 15 | public class KeepLiveReceivers extends BroadcastReceiver{ 16 | @Override 17 | public void onReceive(Context context, Intent intent) { 18 | String action = intent.getAction(); 19 | Log.i("91ysdk",action); 20 | if(KeepLiveUtils.hasNetwork(context) == false){ 21 | return; 22 | } 23 | if (!KeepLiveUtils.isServiceWork(context,"service.keppliveservice.service.OnLineService")){ 24 | Intent startSrv = new Intent(context, OnLineService.class); 25 | startSrv.putExtra("CMD", "TICK"); 26 | context.startService(startSrv); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /app/src/main/java/service/keppliveservice/DateTimeUtil.java: -------------------------------------------------------------------------------- 1 | package service.keppliveservice; 2 | 3 | import java.text.ParseException; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Calendar; 6 | import java.util.Date; 7 | 8 | 9 | public class DateTimeUtil { 10 | 11 | public static String DEFAULTFORMAT = "yyyy-MM-dd HH:mm:ss"; 12 | 13 | public static String getCurDateTime() { 14 | return getCurDateTime(DEFAULTFORMAT); 15 | } 16 | 17 | /** 18 | * 当前时间 19 | * @param pattern 20 | * @return 21 | */ 22 | public static String getCurDateTime(String pattern) { 23 | return formatCalendar(Calendar.getInstance(),pattern); 24 | } 25 | 26 | public static String formatCalendar(Calendar calendar){ 27 | return formatCalendar(calendar,DEFAULTFORMAT); 28 | } 29 | 30 | public static String formatCalendar(Calendar calendar, String pattern){ 31 | SimpleDateFormat sdf = new SimpleDateFormat(pattern); 32 | //sdf.setTimeZone(TimeZone.getTimeZone(timeZone)); 33 | return sdf.format(calendar.getTime()); 34 | } 35 | 36 | public static Date parseDate(String date) throws ParseException { 37 | if(date == null) 38 | return null; 39 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 40 | return sdf.parse(date); 41 | } 42 | 43 | public static Date parseDate(String date, String pattern) throws ParseException { 44 | if(date == null) 45 | return null; 46 | SimpleDateFormat sdf = new SimpleDateFormat(pattern); 47 | return sdf.parse(date); 48 | } 49 | 50 | public static String formatDate(Date date, String pattern){ 51 | if(date==null) 52 | return ""; 53 | Calendar calendar = Calendar.getInstance(); 54 | calendar.setTime(date); 55 | return formatCalendar(calendar,pattern); 56 | } 57 | 58 | public static String formatDate(Date date){ 59 | return formatDate(date,DEFAULTFORMAT); 60 | } 61 | 62 | public static Calendar parseString(String dateStr, String pattern) throws ParseException { 63 | SimpleDateFormat sdf = new SimpleDateFormat(pattern); 64 | Date date = sdf.parse(dateStr); 65 | Calendar calendar = Calendar.getInstance(); 66 | calendar.setTime(date); 67 | return calendar; 68 | } 69 | public static String convertDateTimeStrFormat(String dateStr, String pattern, String newPattern) throws ParseException { 70 | return DateTimeUtil.formatCalendar(DateTimeUtil.parseString(dateStr,pattern),newPattern); 71 | } 72 | 73 | public static Calendar parseString(String dateStr)throws ParseException { 74 | return parseString(dateStr,DEFAULTFORMAT); 75 | } 76 | 77 | 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/service/keppliveservice/service/MyJobService.java: -------------------------------------------------------------------------------- 1 | package service.keppliveservice.service; 2 | 3 | import android.annotation.TargetApi; 4 | import android.app.job.JobInfo; 5 | import android.app.job.JobParameters; 6 | import android.app.job.JobScheduler; 7 | import android.app.job.JobService; 8 | import android.content.ComponentName; 9 | import android.content.Context; 10 | import android.content.Intent; 11 | import android.os.Build; 12 | import android.util.Log; 13 | import android.widget.Toast; 14 | 15 | import service.keppliveservice.KeepLiveUtils; 16 | 17 | /** 18 | * Created by haifeng on 2017/8/25. 19 | */ 20 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 21 | public class MyJobService extends JobService{ 22 | 23 | @Override 24 | public boolean onStartJob(JobParameters params) { 25 | Log.d("91ySdk", "onStartJob"); 26 | startService(); 27 | return false; 28 | } 29 | 30 | @Override 31 | public boolean onStopJob(JobParameters params) { 32 | Log.i("91ySdk","onStopJob"); 33 | return false; 34 | } 35 | 36 | @Override 37 | public int onStartCommand(Intent intent, int flags, int startId) { 38 | Log.i("91ySdk","onStartCommand"); 39 | try { 40 | int id = 1; 41 | JobInfo.Builder builder = new JobInfo.Builder(id, 42 | new ComponentName(getPackageName(), MyJobService.class.getName() )); 43 | builder.setPeriodic(60*1000); //间隔5分钟毫秒调用onStartJob函数 44 | builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY); //有网络的时候唤醒 45 | JobScheduler jobScheduler = (JobScheduler)this.getSystemService(Context.JOB_SCHEDULER_SERVICE); 46 | int ret = jobScheduler.schedule(builder.build()); 47 | } catch (Exception ex) { 48 | ex.printStackTrace(); 49 | } 50 | startService(); 51 | return super.onStartCommand(intent, flags, startId); 52 | } 53 | 54 | public void startService(){ 55 | boolean isOnLineServiceWork = KeepLiveUtils.isServiceWork(this, "service.keppliveservice.service.OnLineService"); 56 | boolean isKeepLiveServiceWork = KeepLiveUtils.isServiceWork(this, "service.keppliveservice.service.KeepLiveService"); 57 | if(!isOnLineServiceWork|| 58 | !isKeepLiveServiceWork){ 59 | this.startService(new Intent(this,OnLineService.class)); 60 | this.startService(new Intent(this,KeepLiveService.class)); 61 | Toast.makeText(this, "进程启动", Toast.LENGTH_SHORT).show(); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 36 | 37 | 38 | 39 | 43 | 44 | 45 | 46 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /app/src/main/java/service/keppliveservice/service/KeepLiveService.java: -------------------------------------------------------------------------------- 1 | package service.keppliveservice.service; 2 | 3 | import android.app.Service; 4 | import android.content.Intent; 5 | import android.os.Handler; 6 | import android.os.IBinder; 7 | import android.os.Message; 8 | import android.os.RemoteException; 9 | import android.widget.Toast; 10 | 11 | import service.keppliveservice.KeepLiveUtils; 12 | import service.keppliveservice.StrongService; 13 | 14 | 15 | /** 16 | * Created by haifeng on 2017/8/24. 17 | */ 18 | 19 | public class KeepLiveService extends Service { 20 | 21 | private Handler handler = new Handler() { 22 | public void handleMessage(android.os.Message msg) { 23 | switch (msg.what) { 24 | case 1: 25 | startOnlineService(); 26 | break; 27 | 28 | default: 29 | break; 30 | } 31 | 32 | }; 33 | }; 34 | 35 | @Override 36 | public void onCreate() { 37 | 38 | Toast.makeText(KeepLiveService.this, "Service2 启动中...", Toast.LENGTH_SHORT).show(); 39 | startOnlineService(); 40 | /* 41 | * 此线程用监听Service2的状态 42 | */ 43 | new Thread() { 44 | public void run() { 45 | while (true) { 46 | boolean isRun = KeepLiveUtils.isServiceWork(KeepLiveService.this,"service.keppliveservice.service.OnLineService"); 47 | if (!isRun) { 48 | Message msg = Message.obtain(); 49 | msg.what = 1; 50 | handler.sendMessage(msg); 51 | } 52 | try { 53 | Thread.sleep(1); 54 | } catch (InterruptedException e) { 55 | e.printStackTrace(); 56 | } 57 | } 58 | }; 59 | }.start(); 60 | } 61 | 62 | @Override 63 | public IBinder onBind(Intent intent) { 64 | return (IBinder) startS1; 65 | } 66 | 67 | @Override 68 | public int onStartCommand(Intent intent, int flags, int startId) { 69 | return START_STICKY; 70 | } 71 | 72 | /** 73 | * 判断Service1是否还在运行,如果不是则启动Service1 74 | */ 75 | private void startOnlineService() { 76 | boolean isRun = KeepLiveUtils.isServiceWork(KeepLiveService.this, 77 | "service.keppliveservice.service.OnLineService"); 78 | if (isRun == false) { 79 | try { 80 | startS1.StartService(); 81 | } catch (RemoteException e) { 82 | e.printStackTrace(); 83 | } 84 | } 85 | } 86 | 87 | /** 88 | * 使用aidl 启动Service1 89 | */ 90 | private StrongService startS1 = new StrongService.Stub() { 91 | 92 | @Override 93 | public void StartService() throws RemoteException { 94 | Intent i = new Intent(getBaseContext(), OnLineService.class); 95 | getBaseContext().startService(i); 96 | } 97 | 98 | @Override 99 | public void stopService() throws RemoteException { 100 | Intent i = new Intent(getBaseContext(), OnLineService.class); 101 | getBaseContext().stopService(i); 102 | } 103 | }; 104 | 105 | @Override 106 | public void onTrimMemory(int level) { 107 | startOnlineService(); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /app/src/main/java/service/keppliveservice/Util.java: -------------------------------------------------------------------------------- 1 | package service.keppliveservice; 2 | 3 | import android.app.ActivityManager; 4 | import android.content.Context; 5 | import android.net.ConnectivityManager; 6 | import android.net.NetworkInfo; 7 | 8 | import java.security.MessageDigest; 9 | import java.util.List; 10 | 11 | public class Util { 12 | 13 | public static char convertDigit(int value) { 14 | value &= 0x0f; 15 | if (value >= 10) 16 | return ((char) (value - 10 + 'a')); 17 | else 18 | return ((char) (value + '0')); 19 | } 20 | 21 | public static String convert(final byte bytes[]) { 22 | 23 | StringBuffer sb = new StringBuffer(bytes.length * 2); 24 | for (int i = 0; i < bytes.length; i++) { 25 | sb.append(convertDigit((int) (bytes[i] >> 4))); 26 | sb.append(convertDigit((int) (bytes[i] & 0x0f))); 27 | } 28 | return (sb.toString()); 29 | 30 | } 31 | 32 | public static String convert(final byte bytes[], int pos, int len) { 33 | 34 | StringBuffer sb = new StringBuffer(len * 2); 35 | for (int i = pos; i < pos+len; i++) { 36 | sb.append(convertDigit((int) (bytes[i] >> 4))); 37 | sb.append(convertDigit((int) (bytes[i] & 0x0f))); 38 | } 39 | return (sb.toString()); 40 | 41 | } 42 | 43 | public static byte[] md5Byte(String encryptStr) throws Exception { 44 | MessageDigest md = MessageDigest.getInstance("MD5"); 45 | md.update(encryptStr.getBytes("UTF-8")); 46 | return md.digest(); 47 | } 48 | 49 | public static String md5(String encryptStr) throws Exception { 50 | MessageDigest md = MessageDigest.getInstance("MD5"); 51 | md.update(encryptStr.getBytes("UTF-8")); 52 | byte[] digest = md.digest(); 53 | StringBuffer md5 = new StringBuffer(); 54 | for (int i = 0; i < digest.length; i++) { 55 | md5.append(Character.forDigit((digest[i] & 0xF0) >> 4, 16)); 56 | md5.append(Character.forDigit((digest[i] & 0xF), 16)); 57 | } 58 | 59 | encryptStr = md5.toString(); 60 | return encryptStr; 61 | } 62 | 63 | public static boolean hasNetwork(Context context) { 64 | ConnectivityManager cm = 65 | (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 66 | NetworkInfo netInfo = cm.getActiveNetworkInfo(); 67 | if (netInfo != null && netInfo.isConnected()) { 68 | return true; 69 | } 70 | return false; 71 | } 72 | 73 | /** 74 | * 判断某个服务是否正在运行的方法 75 | * 76 | * @param mContext 77 | * @param serviceName 78 | * 是包名+服务的类名(例如:com.beidian.test.service.BasicInfoService ) 79 | * @return 80 | */ 81 | public static boolean isServiceWork(Context mContext, String serviceName) { 82 | boolean isWork = false; 83 | ActivityManager myAM = (ActivityManager) mContext 84 | .getSystemService(Context.ACTIVITY_SERVICE); 85 | List myList = myAM.getRunningServices(100); 86 | if (myList.size() <= 0) { 87 | return false; 88 | } 89 | for (int i = 0; i < myList.size(); i++) { 90 | String mName = myList.get(i).service.getClassName().toString(); 91 | if (mName.equals(serviceName)) { 92 | isWork = true; 93 | break; 94 | } 95 | } 96 | return isWork; 97 | } 98 | 99 | /** 100 | * 判断进程是否运行 101 | * 102 | * @return 103 | */ 104 | public static boolean isProessRunning(Context context, String proessName) { 105 | 106 | boolean isRunning = false; 107 | ActivityManager am = (ActivityManager) context 108 | .getSystemService(Context.ACTIVITY_SERVICE); 109 | 110 | List lists = am.getRunningAppProcesses(); 111 | for (ActivityManager.RunningAppProcessInfo info : lists) { 112 | if (info.processName.equals(proessName)) { 113 | isRunning = true; 114 | } 115 | } 116 | 117 | return isRunning; 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /app/src/main/java/service/keppliveservice/KeepLiveUtils.java: -------------------------------------------------------------------------------- 1 | package service.keppliveservice; 2 | 3 | import android.app.ActivityManager; 4 | import android.content.ComponentName; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.net.ConnectivityManager; 8 | import android.net.NetworkInfo; 9 | import android.net.Uri; 10 | import android.os.Build; 11 | import android.provider.Settings; 12 | import android.util.Log; 13 | 14 | import java.util.List; 15 | 16 | /** 17 | * Created by haifeng on 2017/8/29. 18 | */ 19 | 20 | public class KeepLiveUtils { 21 | 22 | /** 23 | * Get Mobile Type 24 | * 25 | * @return 26 | */ 27 | private static String getMobileType() { 28 | return Build.MANUFACTURER; 29 | } 30 | 31 | /** 32 | * GoTo Open Self Setting Layout 33 | * Compatible Mainstream Models 兼容市面主流机型 34 | * 35 | * @param context 36 | */ 37 | public static void jumpStartInterface(Context context) { 38 | Intent intent = new Intent(); 39 | try { 40 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 41 | Log.e("HLQ_Struggle", "******************当前手机型号为:" + getMobileType()); 42 | ComponentName componentName = null; 43 | if (getMobileType().equals("Xiaomi")) { // 红米Note4测试通过 44 | componentName = new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"); 45 | } else if (getMobileType().equals("Letv")) { // 乐视2测试通过 46 | intent.setAction("com.letv.android.permissionautoboot"); 47 | } else if (getMobileType().equals("samsung")) { // 三星Note5测试通过 48 | componentName = new ComponentName("com.samsung.android.sm_cn", "com.samsung.android.sm.ui.ram.AutoRunActivity"); 49 | } else if (getMobileType().equals("HUAWEI")) { // 华为测试通过 50 | componentName = new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"); 51 | } else if (getMobileType().equals("vivo")) { // VIVO测试通过 52 | componentName = ComponentName.unflattenFromString("com.iqoo.secure/.safeguard.PurviewTabActivity"); 53 | } else if (getMobileType().equals("Meizu")) { //万恶的魅族 54 | // 通过测试,发现魅族是真恶心,也是够了,之前版本还能查看到关于设置自启动这一界面,系统更新之后,完全找不到了,心里默默Fuck! 55 | // 针对魅族,我们只能通过魅族内置手机管家去设置自启动,所以我在这里直接跳转到魅族内置手机管家界面,具体结果请看图 56 | componentName = ComponentName.unflattenFromString("com.meizu.safe/.permission.PermissionMainActivity"); 57 | } else if (getMobileType().equals("OPPO")) { // OPPO R8205测试通过 58 | // componentName = ComponentName.unflattenFromString("com.oppo.safe/.permission.startup.StartupAppListActivity"); 59 | componentName = ComponentName.unflattenFromString("com.oppo.safe/.permission.startup.StartupAppListActivity"); 60 | Intent intentOppo = new Intent(); 61 | intentOppo.setClassName("com.oppo.safe/.permission.startup", "StartupAppListActivity"); 62 | if (context.getPackageManager().resolveActivity(intentOppo, 0) == null) { 63 | componentName = ComponentName.unflattenFromString("com.coloros.safecenter/.startupapp.StartupAppListActivity"); 64 | } 65 | } else if (getMobileType().equals("ulong")) { // 360手机 未测试 66 | componentName = new ComponentName("com.yulong.android.coolsafe", ".ui.activity.autorun.AutoRunListActivity"); 67 | } else { 68 | // 以上只是市面上主流机型,由于公司你懂的,所以很不容易才凑齐以上设备 69 | // 针对于其他设备,我们只能调整当前系统app查看详情界面 70 | // 在此根据用户手机当前版本跳转系统设置界面 71 | if (Build.VERSION.SDK_INT >= 9) { 72 | intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS"); 73 | intent.setData(Uri.fromParts("package", context.getPackageName(), null)); 74 | } else if (Build.VERSION.SDK_INT <= 8) { 75 | intent.setAction(Intent.ACTION_VIEW); 76 | intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails"); 77 | intent.putExtra("com.android.settings.ApplicationPkgName", context.getPackageName()); 78 | } 79 | } 80 | intent.setComponent(componentName); 81 | context.startActivity(intent); 82 | } catch (Exception e) {//抛出异常就直接打开设置页面 83 | intent = new Intent(Settings.ACTION_SETTINGS); 84 | context.startActivity(intent); 85 | } 86 | } 87 | 88 | public static boolean hasNetwork(Context context) { 89 | ConnectivityManager cm = 90 | (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 91 | NetworkInfo netInfo = cm.getActiveNetworkInfo(); 92 | if (netInfo != null && netInfo.isConnected()) { 93 | return true; 94 | } 95 | return false; 96 | } 97 | 98 | /** 99 | * 判断某个服务是否正在运行的方法 100 | * 101 | * @param mContext 102 | * @param serviceName 103 | * 是包名+服务的类名(例如:com.beidian.test.service.BasicInfoService ) 104 | * @return 105 | */ 106 | public static boolean isServiceWork(Context mContext, String serviceName) { 107 | boolean isWork = false; 108 | ActivityManager myAM = (ActivityManager) mContext 109 | .getSystemService(Context.ACTIVITY_SERVICE); 110 | List myList = myAM.getRunningServices(100); 111 | if (myList.size() <= 0) { 112 | return false; 113 | } 114 | for (int i = 0; i < myList.size(); i++) { 115 | String mName = myList.get(i).service.getClassName().toString(); 116 | if (mName.equals(serviceName)) { 117 | isWork = true; 118 | break; 119 | } 120 | } 121 | return isWork; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 15 | 16 | 20 | 21 | 24 | 25 | 31 | 32 | 33 | 34 | 38 | 39 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 57 | 58 | 61 | 62 | 68 | 69 | 70 | 73 | 74 | 80 | 81 |