java script 安卓_创建Android NativeScript插件

我正在尝试创建一个允许NativeScript应用程序连接到MQTT服务器的插件 . 当我尝试运行应用程序时,我的应用程序中出现以下错误:

java.lang.RuntimeException:无法启动活动ComponentInfo {org.nativescript.testMQTT / com.tns.NativeScriptActivity}:com.tns.NativeScriptException:调用js方法onCreate失败TypeError:无法读取未定义文件的属性'paho':“ ,line:1,column:265 StackTrace:Frame:function:'NativeScriptMQTTClient',file:'/ data / data / org.nativescript.testMQTT / files / app / tns_modules / nativescript-mqtt / mqtt.js',line:8 ,column:44 Frame:function:'',file:'/ data / data / org.nativescript.testMQTT / files / app / main-page.js',line:4,column:14 Frame:function:'require' ,file:'',line:1,column:266 Frame:function:'global.loadModule',file:'/ data / data / org.nativescript.testMQTT / files / app / tns_modules / globals / globals.js', line:19,column:16 Frame:function:'resolvePageFromEntry',file:'/ data / data / org.nativescript.testMQTT / files / app / tns_modules / ui / frame / frame-common.js',line:72, column:40 Frame:function:'Frame.navigate',file:'/ data / data / org.nativescript.testMQTT / files / app / tns_modules / UI / FR

我在mqtt.android.ts文件中使用以下代码与Paho Java库:

export class NativeScriptMQTTClient {

private _topic: String;

private _content: String;

private _qos: number;

private _broker: String;

private _clientId: String;

private _persistance: org.eclipse.paho.client.mqttv3.persist.MemoryPersistance;

private _client: org.eclipse.paho.client.mqttv3.MqttClient;

private _connectOptions: org.eclipse.paho.client.mqttv3.MqttConnectOptions;

constructor(topic: String, qos: number, broker: string, clientId: String) {

this._topic = topic;

this._qos = qos;

this._broker = broker;

this._clientId = clientId;

this._persistance = new org.eclipse.paho.client.mqttv3.persist.MemoryPersistance();

}

connect() {

this._client = new org.eclipse.paho.client.mqttv3.MqttClient(this._broker, this._clientId, this._persistance);

this._connectOptions = new org.eclipse.paho.client.mqttv3.MqttConnectOptions();

this._connectOptions.setCleanSession(true);

console.log("Connecting to the broker: " + this._broker);

this._client.connect(this._connectOptions);

console.log("Connected to the broker: " + this._broker);

console.log("Publishing message: Hello from NativeScript (Morné)");

this._client.publish(this._topic, "Hello from NativeScript (Morné)");

console.log("Published message: Hello from NativeScript (Morné)");

console.log("Disconnecting from the broker: " + this._broker);

this._client.disconnect();

console.log("Disconnected from the broker: " + this._broker);

}

}

我在main-page.ts文件中有以下代码:

import {NativeScriptMQTTClient} from "nativescript-mqtt";

let client: NativeScriptMQTTClient = new NativeScriptMQTTClient("MQTT Examples", 2, "tcp://iot.eclipse.org:1883", "NativeScriptClient");

client.connect();

任何帮助将不胜感激 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值