undefined - NativeScript JobScheduler JobService.class 未定义
问题描述
我尝试在JobScheduler
在设置组件值的第一行,我收到此错误:
ERROR TypeError: Cannot read property 'MyJobService' of undefined
这两个文件都在同一个文件夹中,并且昨天都正常工作。
- 为了确定,我清理了平台文件夹,因为我将一些图片拖到
drawble
文件夹中app_Resources
,我不得不再次构建项目,也许有些东西已经改变了。但它没有帮助。
什么会导致这个问题?我错过了什么吗?
JobScheduler.js:
function scheduleJob(context) {
var component = new android.content.ComponentName(context, com.tns.notifications.MyJobService.class);
const builder = new android.app.job.JobInfo.Builder(1, component);
builder.setPeriodic(15 * 60 * 1000);
builder.setOverrideDeadline(0);
const jobScheduler = context.getSystemService(android.content.Context.JOB_SCHEDULER_SERVICE);
console.log("Job Scheduled: " + jobScheduler.schedule(builder.build()));
}
module.exports.scheduleJob = scheduleJob;
MyJobService.js:
android.app.job.JobService.extend("com.tns.notifications.MyJobService", {
onStartJob: function(params) {
console.log("Job execution ...");
var utils = require("utils/utils");
var context = utils.ad.getApplicationContext();
var builder = new android.app.Notification.Builder(context);
console.log("setting notification head and body")
builder.setContentTitle("notification triggered ")
.setAutoCancel(true)
.setColor(android.R.color.holo_purple)//getResources().getColor(R.color.colorAccent))
.setContentText("body)
.setVibrate([100, 200, 100])
.setSmallIcon(android.R.drawable.btn_star_big_on);
var mainIntent = new android.content.Intent(context, com.tns.NativeScriptActivity.class);
var mNotificationManager = context.getSystemService(android.content.Context.NOTIFICATION_SERVICE);
const channelId = "my_channel_01";
const name = "Channel name";
const description = "Channel description";
const importance = android.app.NotificationManager.IMPORTANCE_LOW;
if (android.os.Build.VERSION.SDK_INT >= 26) {
console.log("api level is good",android.os.Build.VERSION.SDK_INT)
}
const mChannel = new android.app.NotificationChannel(channelId, name,importance);
mChannel.setDescription(description);
mChannel.enableLights(true);
mChannel.enableVibration(true);
mNotificationManager.createNotificationChannel(mChannel);
builder.setChannelId(channelId);
mNotificationManager.notify(1, builder.build());
return false;
},
onStopJob: function() {
console.log("Stopping job ...");
}
});
解决方案
推荐阅读
- r - 根据前一列的值替换多列中的值
- ansible - 使用多个嵌套主机变量时匹配单个自定义主机库存变量
- powershell - 用于将逗号分隔值转换为行并输出为新 CSV 文件的 Powershell 脚本
- ruby - 用于打印类中所有方法调用和返回的 Ruby 模块
- vb.net - VB.NET Linq 查询左外连接左为空
- python - main() 变量未定义
- java - GUI 计数器的重置按钮
- python - 带有聊天客户端的 Flask webapp(使用 websockets 连接到另一台服务器)
- c# - 带有 UID 字段的 X500DistinguishedName
- android - Google Mobiles Ads Creative Preview not working