Android保活

平常接触到的保活

自启动保活 系统通知权限

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class MyNotificationService extends NotificationListenerService {
private String TAG = MyNotificationService.class.getName();
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
Log.d(TAG, "onNotificationPosted: ");
}
@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
Log.d(TAG, "onNotificationRemoved: ");
Intent intent = new Intent(this, BackgroundService.class);
startService(intent);
}
}

跳转

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public static void goNLPermission(Context context) {
try {
Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
context.startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Notification keep live
*/
goNLPermission(this);
Intent notificationService = new Intent(this, MyNotificationService.class);
startService(notificationService);