首页

android 进程保活的四种方式 示例源码

java

2020-7-9

package com.clock.daemon;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.clock.daemon.service.BackgroundService;
import com.clock.daemon.service.GrayService;
import com.clock.daemon.service.WhiteService;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private final static String TAG = MainActivity.class.getSimpleName();
    /**
     * 黑色唤醒广播的action
     */
    private final static String BLACK_WAKE_ACTION = "com.wake.black";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findViewById(R.id.btn_white).setOnClickListener(this);
        findViewById(R.id.btn_gray).setOnClickListener(this);
        findViewById(R.id.btn_black).setOnClickListener(this);
        findViewById(R.id.btn_background_service).setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        int viewId = v.getId();
        if (viewId == R.id.btn_white) { //系统正常的前台Service,白色保活手段
            Intent whiteIntent = new Intent(getApplicationContext(), WhiteService.class);
            startService(whiteIntent);

        } else if (viewId == R.id.btn_gray) {//利用系统漏洞,灰色保活手段(API < 18 和 API >= 18 两种情况)
            Intent grayIntent = new Intent(getApplicationContext(), GrayService.class);
            startService(grayIntent);

        } else if (viewId == R.id.btn_black) { //拉帮结派,黑色保活手段,利用广播唤醒队友
            Intent blackIntent = new Intent();
            blackIntent.setAction(BLACK_WAKE_ACTION);
            sendBroadcast(blackIntent);

            /*AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
            PendingIntent operation = PendingIntent.getBroadcast(this, 123, blackIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            alarmManager.set(AlarmManager.RTC, System.currentTimeMillis(), operation);*/

        } else if (viewId == R.id.btn_background_service) {//普通的后台进程
            Intent bgIntent = new Intent(getApplicationContext(), BackgroundService.class);
            startService(bgIntent);

        }
    }
}
资源下载此资源下载价格为4D币(VIP免费),请先
资源文件列表
AndroidDaemonService-master/.gitignore , 12
AndroidDaemonService-master/.gradle/3.3/taskArtifacts/fileHashes.bin , 135233
AndroidDaemonService-master/.gradle/3.3/taskArtifacts/fileSnapshots.bin , 498575
AndroidDaemonService-master/.gradle/3.3/taskArtifacts/taskArtifacts.bin , 45567
AndroidDaemonService-master/.gradle/3.3/taskArtifacts/taskArtifacts.lock , 17
AndroidDaemonService-master/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin , 24546
AndroidDaemonService-master/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock , 17
AndroidDaemonService-master/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin , 20535
AndroidDaemonService-master/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock , 17
AndroidDaemonService-master/.idea/compiler.xml , 686
AndroidDaemonService-master/.idea/copyright/profiles_settings.xml , 76
AndroidDaemonService-master/.idea/gradle.xml , 577
AndroidDaemonService-master/.idea/libraries/animated_vector_drawable_25_0_1.xml , 607
AndroidDaemonService-master/.idea/libraries/appcompat_v7_25_0_1.xml , 571
AndroidDaemonService-master/.idea/libraries/support_annotations_25_0_1.xml , 507
AndroidDaemonService-master/.idea/libraries/support_compat_25_0_1.xml , 723
AndroidDaemonService-master/.idea/libraries/support_core_ui_25_0_1.xml , 726
AndroidDaemonService-master/.idea/libraries/support_core_utils_25_0_1.xml , 735
AndroidDaemonService-master/.idea/libraries/support_fragment_25_0_1.xml , 729
AndroidDaemonService-master/.idea/libraries/support_media_compat_25_0_1.xml , 741
AndroidDaemonService-master/.idea/libraries/support_v4_25_0_1.xml , 404
AndroidDaemonService-master/.idea/libraries/support_vector_drawable_25_0_1.xml , 604
AndroidDaemonService-master/.idea/misc.xml , 1737
AndroidDaemonService-master/.idea/modules.xml , 294
AndroidDaemonService-master/.idea/runConfigurations.xml , 564
AndroidDaemonService-master/.idea/workspace.xml , 111127
AndroidDaemonService-master/AndroidDaemonService-master.iml , 8750
AndroidDaemonService-master/build.gradle , 857
AndroidDaemonService-master/build/android-profile/profile-2017-08-07-23-22-50-166.rawproto , 1548
AndroidDaemonService-master/build/android-profile/profile-2017-08-07-23-24-26-868.rawproto , 1539
AndroidDaemonService-master/build/android-profile/profile-2017-08-07-23-24-31-958.rawproto , 5138
AndroidDaemonService-master/build/android-profile/profile-2017-08-07-23-26-41-300.rawproto , 5619
AndroidDaemonService-master/build/generated/mockable-android-25.jar , 33866518
AndroidDaemonService-master/build/generated/source/buildConfig/androidTest/debug/com/clock/daemon/test/BuildConfig.java , 449
AndroidDaemonService-master/build/generated/source/buildConfig/debug/com/clock/daemon/BuildConfig.java , 439
AndroidDaemonService-master/build/generated/source/r/debug/android/support/compat/R.java , 252
AndroidDaemonService-master/build/generated/source/r/debug/android/support/coreui/R.java , 252
AndroidDaemonService-master/build/generated/source/r/debug/android/support/coreutils/R.java , 255
AndroidDaemonService-master/build/generated/source/r/debug/android/support/fragment/R.java , 254
AndroidDaemonService-master/build/generated/source/r/debug/android/support/graphics/drawable/animated/R.java , 272
AndroidDaemonService-master/build/generated/source/r/debug/android/support/graphics/drawable/R.java , 263
AndroidDaemonService-master/build/generated/source/r/debug/android/support/mediacompat/R.java , 257
AndroidDaemonService-master/build/generated/source/r/debug/android/support/v4/R.java , 248
AndroidDaemonService-master/build/generated/source/r/debug/android/support/v7/appcompat/R.java , 109194
AndroidDaemonService-master/build/generated/source/r/debug/com/clock/daemon/R.java , 421631
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-af.json , 15600
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-am.json , 15594
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-ar.json , 15602
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-az-rAZ.json , 15032
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-b+sr+Latn.json , 15912
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-be-rBY.json , 15782
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-bg.json , 15606
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-bn-rBD.json , 15786
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-bs-rBA.json , 15782
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-ca.json , 15606
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-cs.json , 15602
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-da.json , 15598
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-de.json , 15602
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-el.json , 15608
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-en-rAU.json , 15774
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-en-rGB.json , 15774
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-en-rIN.json , 15774
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-es-rUS.json , 15784
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-es.json , 15604
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-et-rEE.json , 15784
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-eu-rES.json , 15780
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-fa.json , 15604
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-fi.json , 15598
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-fr-rCA.json , 15784
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-fr.json , 15608
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-gl-rES.json , 15782
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-gu-rIN.json , 15778
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-h720dp-v13.json , 974
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-hdpi-v4.json , 1034
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-hi.json , 15604
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-hr.json , 15602
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-hu.json , 15608
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-hy-rAM.json , 15776
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-in.json , 15604
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-is-rIS.json , 15772
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-it.json , 15600
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-iw.json , 15596
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-ja.json , 15590
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-ka-rGE.json , 15780
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-kk-rKZ.json , 15778
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-km-rKH.json , 15776
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-kn-rIN.json , 15782
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-ko.json , 15586
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-ky-rKG.json , 15778
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-land.json , 3146
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-large-v4.json , 6892
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-ldltr-v21.json , 972
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-lo-rLA.json , 15774
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-lt.json , 15608
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-lv.json , 15606
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-mk-rMK.json , 14292
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-ml-rIN.json , 15782
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-mn-rMN.json , 15776
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-mr-rIN.json , 15782
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-ms-rMY.json , 15780
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-my-rMM.json , 15784
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-nb.json , 15594
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-ne-rNP.json , 15786
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-night-v8.json , 5410
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-nl.json , 15608
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-pa-rIN.json , 15774
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-pl.json , 15604
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-port.json , 950
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-pt-rBR.json , 15784
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-pt-rPT.json , 15784
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-pt.json , 15608
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-ro.json , 15608
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-ru.json , 15606
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-si-rLK.json , 15780
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-sk.json , 15600
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-sl.json , 15604
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-sq-rAL.json , 15780
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-sr.json , 15604
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-sv.json , 15602
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-sw.json , 15600
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-sw600dp-v13.json , 6200
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-ta-rIN.json , 15782
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-te-rIN.json , 15784
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-th.json , 15600
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-tl.json , 15610
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-tr.json , 15600
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-uk.json , 15602
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-ur-rPK.json , 15778
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-uz-rUZ.json , 15782
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-v11.json , 15164
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-v12.json , 3282
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-v13.json , 946
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-v14.json , 9324
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-v16.json , 946
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-v17.json , 11524
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-v18.json , 944
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-v21.json , 79980
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-v22.json , 3282
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-v23.json , 8446
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-v24.json , 3136
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-v25.json , 3280
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-vi.json , 15606
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-w820dp-v13.json , 929
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-xlarge-v4.json , 4680
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-zh-rCN.json , 15760
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-zh-rHK.json , 15760
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-zh-rTW.json , 15760
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values-zu.json , 15606
AndroidDaemonService-master/build/intermediates/blame/res/debug/multi/values.json , 412261
AndroidDaemonService-master/build/intermediates/blame/res/debug/single/anim.json , 3158
AndroidDaemonService-master/build/intermediates/blame/res/debug/single/color-v11.json , 774
最多只能显示150条信息!
没有账号? 忘记密码?

社交账号快速登录