• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MqttAndroidClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.eclipse.paho.android.service.MqttAndroidClient的典型用法代码示例。如果您正苦于以下问题:Java MqttAndroidClient类的具体用法?Java MqttAndroidClient怎么用?Java MqttAndroidClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MqttAndroidClient类属于org.eclipse.paho.android.service包,在下文中一共展示了MqttAndroidClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: startConnect

import org.eclipse.paho.android.service.MqttAndroidClient; //导入依赖的package包/类
private void startConnect(String clientID, String serverIP, String port) {
    //服务器地址
    String  uri ="tcp://";
    uri=uri+serverIP+":"+port;
    Log.d("MainActivity",uri+"  "+clientID);
    /**
     * 连接的选项
     */
    MqttConnectOptions conOpt = new MqttConnectOptions();
    /**设计连接超时时间*/
    conOpt.setConnectionTimeout(3000);
    /**设计心跳间隔时间300秒*/
    conOpt.setKeepAliveInterval(300);
    /**
     * 创建连接对象
     */
     client = new MqttAndroidClient(this,uri, clientID);
    /**
     * 连接后设计一个回调
     */
    client.setCallback(new MqttCallbackHandler(this, clientID));
    /**
     * 开始连接服务器,参数:ConnectionOptions,  IMqttActionListener
     */
    try {
        client.connect(conOpt, null, new ConnectCallBackHandler(this));
    } catch (MqttException e) {
        e.printStackTrace();
    }

}
 
开发者ID:LiuJunb,项目名称:ActiveMQ-MQTT-Android,代码行数:32,代码来源:MainActivity.java


示例2: testMsg

import org.eclipse.paho.android.service.MqttAndroidClient; //导入依赖的package包/类
public void testMsg() throws MqttException {
    final MqttAndroidClient client = RxMqtt.client(RuntimeEnvironment.application, url);
    TestObserver observer = RxMqtt.message(client, topic).doOnNext(new Consumer<MqttMessage>() {
        @Override
        public void accept(MqttMessage msg) throws Exception {
            System.out.println(msg);
        }
    }).test();
    try {
        observer.await(10, SECONDS);
    } catch (InterruptedException e) {
        fail(e.toString());
        e.printStackTrace();
    }
    observer.assertNoErrors();
    //assertTrue(true);
}
 
开发者ID:yongjhih,项目名称:rx-mqtt,代码行数:18,代码来源:RxMqttTest.java


示例3: createClient

import org.eclipse.paho.android.service.MqttAndroidClient; //导入依赖的package包/类
public MqttAndroidClient createClient(String id, String serverURI, String clientId) {
    MqttClientPersistence mqttClientPersistence = new MemoryPersistence();
    MqttAndroidClient client = new MqttAndroidClient(MyApplication.getContext(), serverURI, clientId, mqttClientPersistence);
    client.setCallback(new MqttCallback() {
        @Override
        public void connectionLost(Throwable cause) {
            LogUtil.e("connectionLost");
            EventBus.getDefault().post(new MQTTActionEvent(Constant.MQTTStatusConstant.CONNECTION_LOST, null, cause));

        }

        @Override
        public void messageArrived(String topic, MqttMessage message) throws Exception {
            LogUtil.d("topic is " + topic + ",message is " + message.toString() + ", qos is " + message.getQos());
            EventBus.getDefault().postSticky(new MessageEvent(new EmqMessage(topic, message)));

        }

        @Override
        public void deliveryComplete(IMqttDeliveryToken token) {
            LogUtil.d("deliveryComplete");


        }
    });

    mClients.put(id, client);

    return client;

}
 
开发者ID:emqtt,项目名称:EMQ-Android-Toolkit,代码行数:32,代码来源:MQTTManager.java


示例4: disconnect

import org.eclipse.paho.android.service.MqttAndroidClient; //导入依赖的package包/类
public boolean disconnect(MqttAndroidClient client) {
    if (!isConnected(client)) {
        return true;
    }

    try {
        client.disconnect();
        return true;
    } catch (MqttException e) {
        e.printStackTrace();
        return false;
    }
}
 
开发者ID:emqtt,项目名称:EMQ-Android-Toolkit,代码行数:14,代码来源:MQTTManager.java


示例5: MQTTconect

import org.eclipse.paho.android.service.MqttAndroidClient; //导入依赖的package包/类
public MQTTconect(Context contexto,MqttCallback mqttcallback) {

        //gera um código randômico que serve como identificação do cliente
        clientID = MqttClient.generateClientId()+"circularUFPAapp";
        //cria um objeto MQTTClient android entregando como parametro o endereço o servidor e o id do cliente
        mqttAndroidClient = new MqttAndroidClient(contexto, serverAndress, clientID);
        //configura um objeto CallBack (objeto de chamada caso haja alteração)
        mqttAndroidClient.setCallback(mqttcallback);


    }
 
开发者ID:lasseufpa,项目名称:circular,代码行数:12,代码来源:MQTTconect.java


示例6: createConnection

import org.eclipse.paho.android.service.MqttAndroidClient; //导入依赖的package包/类
/**
 * Creates a connection from persisted information in the database store, attempting
 * to create a {@link MqttAndroidClient} and the client handle.
 * @param clientId The id of the client
 * @param host the server which the client is connecting to
 * @param port the port on the server which the client will attempt to connect to
 * @param context the application context
 * @param tlsConnection true if the connection is secured by SSL
 * @return a new instance of <code>Connection</code>
 */
public static Connection createConnection(String clientHandle, String clientId, String host, int port, Context context, boolean tlsConnection){

    String uri;
    if(tlsConnection) {
        uri = "ssl://" + host + ":" + port;
    } else {
        uri = "tcp://" + host + ":" + port;
    }

    executor = Executors.newFixedThreadPool(1);

    MqttAndroidClient client = new MqttAndroidClient(context, uri, clientId);
    return new Connection(clientHandle, clientId, host, port, context, client, tlsConnection);
}
 
开发者ID:Cirrus-Link,项目名称:Sparkplug,代码行数:25,代码来源:Connection.java


示例7: updateConnection

import org.eclipse.paho.android.service.MqttAndroidClient; //导入依赖的package包/类
public void updateConnection(String clientId, String host, int port, boolean tlsConnection){
    String uri;
    if(tlsConnection) {
        uri = "ssl://" + host + ":" + port;
    } else {
        uri = "tcp://" + host + ":" + port;
    }

    this.clientId = clientId;
    this.host = host;
    this.port = port;
    this.tlsConnection = tlsConnection;
    this.client = new MqttAndroidClient(context, uri, clientId);
}
 
开发者ID:Cirrus-Link,项目名称:Sparkplug,代码行数:15,代码来源:Connection.java


示例8: Connection

import org.eclipse.paho.android.service.MqttAndroidClient; //导入依赖的package包/类
/**
 * Creates a connection object with the server information and the client
 * hand which is the reference used to pass the client around activities
 * @param clientHandle The handle to this <code>Connection</code> object
 * @param clientId The Id of the client
 * @param host The server which the client is connecting to
 * @param port The port on the server which the client will attempt to connect to
 * @param context The application context
 * @param client The MqttAndroidClient which communicates with the service for this connection
 * @param tlsConnection true if the connection is secured by SSL
 */
private Connection(String clientHandle, String clientId, String host,
                   int port, Context context, MqttAndroidClient client, boolean tlsConnection) {
    //generate the client handle from its hash code
    this.clientHandle = clientHandle;
    this.clientId = clientId;
    this.host = host;
    this.port = port;
    this.context = context;
    this.client = client;
    this.tlsConnection = tlsConnection;
    history = new ArrayList<String>();
    String sb = "Client: " +
            clientId +
            " created";
    addAction(sb);

    try {
        sparkplugMetrics.put("Analog 1", new MetricBuilder("Analog 1", MetricDataType.Double, 0D).createMetric());
        sparkplugMetrics.put("Analog 2", new MetricBuilder("Analog 2", MetricDataType.Double, 0D).createMetric());
        sparkplugMetrics.put("Analog 3", new MetricBuilder("Analog 3", MetricDataType.Double, 0D).createMetric());
        sparkplugMetrics.put("Analog 4", new MetricBuilder("Analog 4", MetricDataType.Double, 0D).createMetric());
        sparkplugMetrics.put("Boolean 1", new MetricBuilder("Boolean 1", MetricDataType.Boolean, false).createMetric());
        sparkplugMetrics.put("Boolean 2", new MetricBuilder("Boolean 2", MetricDataType.Boolean, false).createMetric());
        sparkplugMetrics.put("Boolean 3", new MetricBuilder("Boolean 3", MetricDataType.Boolean, false).createMetric());
        sparkplugMetrics.put("Boolean 4", new MetricBuilder("Boolean 4", MetricDataType.Boolean, false).createMetric());

        sparkplugMetrics.put("Scan Code", new MetricBuilder("Scan Code", MetricDataType.String, "").createMetric());
    } catch (Exception e) {
        Log.e(TAG, "Failed to set up metrics", e);
    }

    getGpsLocation();
}
 
开发者ID:Cirrus-Link,项目名称:Sparkplug,代码行数:45,代码来源:Connection.java


示例9: remessage

import org.eclipse.paho.android.service.MqttAndroidClient; //导入依赖的package包/类
/**
 * Auto close client
 * mqttConnectOptions.userName = it }$
 * mqttConnectOptions.password = it.toCharArray() }
 * @param client
 * @param topic
 * @return
 */
@NonNull
@CheckReturnValue
public static Observable<MqttMessage> remessage(@NonNull final MqttAndroidClient client,
                                                @NonNull final String topic) {
    final Observable<MqttMessage> msgObs =
            Observable.create(new ObservableOnSubscribe<MqttMessage>() {
        public void subscribe(
                @NonNull final ObservableEmitter<MqttMessage> emitter) throws Exception {
            client.subscribe(topic, 0, new IMqttMessageListener() {
                @Override
                public void messageArrived(
                        String topic2, @NonNull final MqttMessage message) throws Exception {
                    if (!emitter.isDisposed()) {
                        emitter.onNext(message);
                    }
                }
            });
        }
    });

    if (client.isConnected()) {
        return msgObs;
    } else {
        return reconnect(client).flatMapObservable(
                new Function<IMqttToken, ObservableSource<MqttMessage>>() {
            @Override
            public ObservableSource<MqttMessage> apply(IMqttToken token) throws Exception {
                return msgObs;
            }
        });
    }
}
 
开发者ID:yongjhih,项目名称:rx-mqtt,代码行数:41,代码来源:RxMqtt.java


示例10: connect

import org.eclipse.paho.android.service.MqttAndroidClient; //导入依赖的package包/类
@NonNull
@CheckReturnValue
public static Maybe<IMqttToken> connect(
        @NonNull final MqttAndroidClient client,
        @NonNull final DisconnectedBufferOptions disconnectedBufferOptions) {
    return connect(client, new MqttConnectOptions(), disconnectedBufferOptions);
}
 
开发者ID:yongjhih,项目名称:rx-mqtt,代码行数:8,代码来源:RxMqtt.java


示例11: testConnect

import org.eclipse.paho.android.service.MqttAndroidClient; //导入依赖的package包/类
@Test
public void testConnect() throws MqttException {
    final MqttAndroidClient client = RxMqtt.client(RuntimeEnvironment.application, url);
    TestObserver observer = RxMqtt.connect(client).doOnNext(new Consumer<IMqttToken>() {
        @Override
        public void accept(IMqttToken token) throws Exception {
            System.out.println(token);
        }
    }).test();
    observer.awaitTerminalEvent();
    observer.assertTerminated();
}
 
开发者ID:yongjhih,项目名称:rx-mqtt,代码行数:13,代码来源:RxMqttTest.java


示例12: StatusListener

import org.eclipse.paho.android.service.MqttAndroidClient; //导入依赖的package包/类
public StatusListener(Context ctx, MqttAndroidClient client) {
    this.ctx = ctx;
    this.client = client;
    CharSequence text = "Connection Failure";  //default
    int duration = Toast.LENGTH_SHORT;
    toast = Toast.makeText(ctx, text, duration);

}
 
开发者ID:ibm-messaging,项目名称:mqtt-smartboard,代码行数:9,代码来源:StatusListener.java


示例13: disconnectAllClient

import org.eclipse.paho.android.service.MqttAndroidClient; //导入依赖的package包/类
private void disconnectAllClient() {
    for (MqttAndroidClient client : mClients.values()) {
        disconnect(client);
    }
}
 
开发者ID:emqtt,项目名称:EMQ-Android-Toolkit,代码行数:6,代码来源:MQTTManager.java


示例14: isConnected

import org.eclipse.paho.android.service.MqttAndroidClient; //导入依赖的package包/类
public boolean isConnected(MqttAndroidClient client) {
    return client != null && client.isConnected();
}
 
开发者ID:emqtt,项目名称:EMQ-Android-Toolkit,代码行数:4,代码来源:MQTTManager.java


示例15: getClient

import org.eclipse.paho.android.service.MqttAndroidClient; //导入依赖的package包/类
public MqttAndroidClient getClient(String id) {
    return mClients.get(id);
}
 
开发者ID:emqtt,项目名称:EMQ-Android-Toolkit,代码行数:4,代码来源:MQTTManager.java


示例16: setMQTTclient

import org.eclipse.paho.android.service.MqttAndroidClient; //导入依赖的package包/类
public void setMQTTclient(MqttAndroidClient newMqttClient) {
    this.myMQTTclient = newMqttClient;
}
 
开发者ID:jpmeijers,项目名称:ttnmapperandroid,代码行数:4,代码来源:MyApp.java


示例17: getMyMQTTclient

import org.eclipse.paho.android.service.MqttAndroidClient; //导入依赖的package包/类
public MqttAndroidClient getMyMQTTclient() {
    return this.myMQTTclient;
}
 
开发者ID:jpmeijers,项目名称:ttnmapperandroid,代码行数:4,代码来源:MyApp.java


示例18: createMqttClient

import org.eclipse.paho.android.service.MqttAndroidClient; //导入依赖的package包/类
public void createMqttClient(String serverAddress)
{
    String mqttClientId = MqttClient.generateClientId();
    System.out.println("Server address: " + serverAddress);
    myMQTTclient = new MqttAndroidClient(this.getApplicationContext(), serverAddress, mqttClientId);
}
 
开发者ID:jpmeijers,项目名称:ttnmapperandroid,代码行数:7,代码来源:MyApp.java


示例19: getMqttAndroidClientInstace

import org.eclipse.paho.android.service.MqttAndroidClient; //导入依赖的package包/类
/**
 * 获取MqttAndroidClient实例
 * @return
 */
public static MqttAndroidClient getMqttAndroidClientInstace(){
    if(client!=null)
        return  client;
    return null;
}
 
开发者ID:LiuJunb,项目名称:ActiveMQ-MQTT-Android,代码行数:10,代码来源:MainActivity.java


示例20: onCreate

import org.eclipse.paho.android.service.MqttAndroidClient; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_publish);
    ButterKnife.bind(this);
    setTitle("模拟服务器发布主题");
    initDate();

    /**1.开始发布*/
    btnStartPub.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            /**获取发布的主题*/
            pubTopic = edPubTopic.getText().toString().trim();
            /**获取发布的消息*/
            pubMessage = edPubMessage.getText().toString().trim();
            /**消息的服务质量*/
            int qos=0;
            /**消息是否保持*/
            boolean retain=false;
            /**要发布的消息内容*/
            byte[] message=pubMessage.getBytes();
            if(pubTopic!=null&&!"".equals(pubTopic)){
                /**获取client对象*/
                MqttAndroidClient client = MainActivity.getMqttAndroidClientInstace();
                if(client!=null){
                    try {
                        /**发布一个主题:如果主题名一样不会新建一个主题,会复用*/
                        client.publish(pubTopic,message,qos,retain,null,new PublishCallBackHandler(PublishActivity.this));
                    } catch (MqttException e) {
                        e.printStackTrace();
                    }
                }else{
                    Log.e(PA,"MqttAndroidClient==null");
                }
            }else{
                Toast.makeText(PublishActivity.this,"发布的主题不能为空",Toast.LENGTH_SHORT).show();
            }
        }
    });
}
 
开发者ID:LiuJunb,项目名称:ActiveMQ-MQTT-Android,代码行数:42,代码来源:PublishActivity.java



注:本文中的org.eclipse.paho.android.service.MqttAndroidClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java XRSurfaceData类代码示例发布时间:2022-05-21
下一篇:
Java TransferManagerBuilder类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap