构建了我的项目
我在Google中搜索了几个小时,但是我只有3页有3页,而其中的任何问题都对我有帮助。
im在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" />
我在webpack.config.js中注册了该作业:
const appComponents = [
"tns-core-modules/ui/frame",
"tns-core-modules/ui/frame/activity",
resolve(__dirname, "app/Jobs/TestJobService.js"),
];
我得到了这个错误:
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平台清洁Android,因为我的androidmanifest.xml在构建中没有传播...
我在这里留下问题,如果我可以帮助某人。