//定义前台服务的默认样式。即标题、描述和图标
ForegroundNotification foregroundNotification = new ForegroundNotification("测试","描述", R.mipmap.ic_launcher,
//定义前台服务的通知点击事件
new ForegroundNotificationClickListener() {
@Override
public void foregroundNotificationClick(Context context, Intent intent) {
}
});
//启动保活服务
KeepLive.startWork(this, KeepLive.RunMode.ENERGY, foregroundNotification,
//你需要保活的服务,如socket连接、定时任务等,建议不用匿名内部类的方式在这里写
new KeepLiveService() {
/**
* 运行中
* 由于服务可能会多次自动启动,该方法可能重复调用
*/
@Override
public void onWorking() {
}
/**
* 服务终止
* 由于服务可能会被多次终止,该方法可能重复调用,需同onWorking配套使用,如注册和注销broadcast
*/
@Override
public void onStop() {
}
}
);
<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="android.permission.REORDER_TASKS"/>
<receiver android:name="com.fanjun.keeplive.receiver.NotificationClickReceiver"/>
<activity android:name="com.fanjun.keeplive.activity.OnePixelActivity"/>
<service android:name="com.fanjun.keeplive.service.LocalService"/>
<service android:name="com.fanjun.keeplive.service.JobHandlerService" android:permission="android.permission.BIND_JOB_SERVICE"/>
<service android:name="com.fanjun.keeplive.service.RemoteService" android:process=":remote"/>
<dependency>
<groupId>com.fanjun</groupId>
<artifactId>keeplive</artifactId>
<version>1.0.8</version>
<type>pom</type>
</dependency>
implementation 'com.fanjun:keeplive:1.0.8'