onHandleWork没有触发。该服务在 android 10 以下运行良好。
class IncidentImageUploadService : JobIntentService() {
private var eventModel: String? = null
private var incidentId: Int? = null
private var sS3Client: AmazonS3Client? = null
private var sMobileClient: AWSCredentialsProvider? = null
private var sTransferUtility: TransferUtility? = null
override fun onHandleWork(intent: Intent) {
eventModel = intent.getStringExtra(BeontConstant.UPLOAD_ADD_INCIDENT_IMAGE)
incidentId = intent.getIntExtra(BeontConstant.INCIDENT_ID, -1)
if (eventModel != null) {
if (!eventModel!!.isNullOrEmpty()) {
println("message"+eventModel)
}
}
}
override fun onStopCurrentWork(): Boolean {
return true
}
companion object {
val JOB_ID = 23
fun enqueueWork(context: Context, work: Intent) {
enqueueWork(context, IncidentImageUploadService::class.java, JOB_ID, work)
}
}
}
这就是我启动 JobIntentService 的方式:
val intentUpload = Intent(activity!!, IncidentImageUploadService::class.java)
intentUpload.putExtra(BeontConstant.UPLOAD_ADD_INCIDENT_IMAGE, fileName)
intentUpload.putExtra(BeontConstant.INCIDENT_ID, model.id)
IncidentImageUploadService.enqueueWork(activity!!, intentUpload)
这就是我在应用程序下的清单中定义服务的方式:
<service
android:name=".services.IncidentImageUploadService"
android:permission="android.permission.BIND_JOB_SERVICE" />
任何帮助将非常感激。谢谢