Android 如何在nativescript vue中创建作业服务

Android 如何在nativescript vue中创建作业服务,android,vue.js,nativescript,nativescript-vue,jobservice,Android,Vue.js,Nativescript,Nativescript Vue,Jobservice,我在谷歌上搜索了几个小时,但我只得到了3页关于这个问题的页面,没有一个对我有帮助 tns上的即时通讯:5.3.0 TestJobService.js android.app.job.JobService.extend("org.nativescipt.ITPalert.TestJobService", { onStartJob() { console.log("Job execution ..."); // here you can do whatever you want //t

我在谷歌上搜索了几个小时,但我只得到了3页关于这个问题的页面,没有一个对我有帮助

tns上的即时通讯:5.3.0

TestJobService.js

android.app.job.JobService.extend("org.nativescipt.ITPalert.TestJobService", {
 onStartJob() {
  console.log("Job execution ...");
  // here you can do whatever you want
  //this.jobFinished(params, true); //this ends the job if successful, if not `return false;`
  return true;
 },

 onStopJob() {
  console.log("Stopping job ...");
  return true; //returning true makes the task reschedule
 },
});
Home.vue

startBackground() {
    const context = utils.ad.getApplicationContext();
    const component = new android.content.ComponentName(context, org.nativescipt.ITPalert.TestJobService.class);
    const builder = new android.app.job.JobInfo.Builder(1, component);
    builder.setRequiredNetworkType(android.app.job.JobInfo.NETWORK_TYPE_ANY);
    builder.setMinimumLatency(1000 * 60)
    builder.setOverrideDeadline(1000 * 100)
    builder.setPersisted(true)

    const jobScheduler = context.getSystemService(android.content.Context.JOB_SCHEDULER_SERVICE);
    const service = jobScheduler.schedule(builder.build());
    console.log(`Job Scheduled: ${jobScheduler.schedule(builder.build())}`);
  },
在我的AndroidManifest.xml中,我有:

<service android:name="org.nativescipt.ITPalert.TestJobService"
                    android:permission="android.permission.BIND_JOB_SERVICE"
                    android:enabled="true"
                    android:exported="false" />
我得到了这个错误:

System.err: com.tns.NativeScriptException:
System.err: Calling js method onClick failed
System.err:
System.err: Error: java.lang.IllegalArgumentException: No such service ComponentInfo{org.nativescript.ITPalert/org.nativescipt.ITPalert.TestJobService}
System.err:     android.os.Parcel.readException(Parcel.java:1963)
System.err:     android.os.Parcel.readException(Parcel.java:1905)
System.err:     android.app.job.IJobScheduler$Stub$Proxy.schedule(IJobScheduler.java:180)
System.err:     android.app.JobSchedulerImpl.schedule(JobSchedulerImpl.java:44)
System.err:     com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1203)
System.err:     com.tns.Runtime.callJSMethodImpl(Runtime.java:1083)
System.err:     com.tns.Runtime.callJSMethod(Runtime.java:1070)
System.err:     com.tns.Runtime.callJSMethod(Runtime.java:1050)
System.err:     com.tns.Runtime.callJSMethod(Runtime.java:1042)
System.err:     com.tns.gen.java.lang.Object_vendor_30697_26_ClickListenerImpl.onClick(Object_vendor_30697_26_ClickListenerImpl.java:17)
System.err:     android.view.View.performClick(View.java:6896)

我用--bundle和--hmr构建了我的项目。

我需要运行:tns platform clean android,因为我的AndroidManifest.xml没有在构建中传播


我把问题留在这里,如果我能帮助别人。

不要忘记权限
谢谢你的回答,这对我很有帮助:)
System.err: com.tns.NativeScriptException:
System.err: Calling js method onClick failed
System.err:
System.err: Error: java.lang.IllegalArgumentException: No such service ComponentInfo{org.nativescript.ITPalert/org.nativescipt.ITPalert.TestJobService}
System.err:     android.os.Parcel.readException(Parcel.java:1963)
System.err:     android.os.Parcel.readException(Parcel.java:1905)
System.err:     android.app.job.IJobScheduler$Stub$Proxy.schedule(IJobScheduler.java:180)
System.err:     android.app.JobSchedulerImpl.schedule(JobSchedulerImpl.java:44)
System.err:     com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1203)
System.err:     com.tns.Runtime.callJSMethodImpl(Runtime.java:1083)
System.err:     com.tns.Runtime.callJSMethod(Runtime.java:1070)
System.err:     com.tns.Runtime.callJSMethod(Runtime.java:1050)
System.err:     com.tns.Runtime.callJSMethod(Runtime.java:1042)
System.err:     com.tns.gen.java.lang.Object_vendor_30697_26_ClickListenerImpl.onClick(Object_vendor_30697_26_ClickListenerImpl.java:17)
System.err:     android.view.View.performClick(View.java:6896)