资源简介
mqtt android使用源码 链接ActiveMQ服务器,其中的代码直接复制在你的项目中就行,记得把包名都改一下,不然会报错,还有你要下载mqttclient的jar包并引用在项目中不然导入的client包会找不到
代码片段和文件信息
package com.youngch.common.myapplication.mqtt;
import android.content.Context;
import com.youngch.common.myapplication.mqtt.service.MqttActionListener;
import com.youngch.common.myapplication.mqtt.service.MqttAndroidClient;
import org.eclipse.paho.client.mqttv3.IMqttActionListener;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
/**
* Created by ZhangHs on 2018/4/19.
* 对mqtt的封装
*/
public class MqttFactory {
private final Context context;
private final String serverIP;
private final String port;
private final boolean autoConnect;
private final int connectionTimeout;
private final int keepAliveInterval;
private final String clientId;
private final MqttCallback callback;
private MqttAndroidClient client;
private MqttConnectOptions options;
private MqttActionListener actionListener;
public MqttFactory(Builder builder) {
this.context = builder.context;
this.serverIP = builder.serverIP;
this.autoConnect = builder.autoConnect;
this.connectionTimeout = builder.connectionTimeout;
this.keepAliveInterval =builder. keepAliveInterval;
this.clientId = builder.clientId;
this.callback=builder.callback;
this.port=builder.port;
init();
}
private void init(){
client=new MqttAndroidClient(context“tcp://“+serverIP+“:“+portclientId);
client.setCallback(callback);
options=new MqttConnectOptions();
options.setAutomaticReconnect(autoConnect);
options.setConnectionTimeout(connectionTimeout);
options.setKeepAliveInterval(keepAliveInterval);
}
public void connect(){
try {
client.connect(options null actionListener=new MqttActionListener(MqttActionListener.TYPE.CONNECTMQTT));
} catch (MqttException e) {
e.printStackTrace();
}
}
public static class Builder {
private Context context;
private String serverIP;
private String port;
private boolean autoConnect;
private int connectionTimeout;
private int keepAliveInterval;
private String clientId;
private MqttCallback callback;
public Builder(Context context) {
this.context = context;
}
public Builder port(String port) {
this.port = port;
return this;
}
public Builder serverIP(String serverIP) {
this.serverIP = serverIP;
return this;
}
public Builder clientId(String clientId) {
this.clientId = clientId;
return this;
}
public Builder keepAliveInterval(int keepAliveInterval) {
this.keepAliveInterval = keepAliveInterval;
return this;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-04-24 13:23 mqtt\
文件 4657 2018-04-20 15:27 mqtt\MqttFactory.java
文件 1887 2018-04-20 15:27 mqtt\MqttIn.java
目录 0 2018-04-20 15:29 mqtt\service\
文件 5083 2018-04-20 14:17 mqtt\service\AlarmPingSender.java
文件 521 2018-04-20 14:17 mqtt\service\BuildConfig.java
文件 10895 2018-04-20 15:29 mqtt\service\Databa
文件 672 2018-04-20 15:29 mqtt\service\MessageStore.java
文件 1846 2018-04-20 15:27 mqtt\service\MqttActionListener.java
文件 26588 2018-04-20 15:27 mqtt\service\MqttAndroidClient.java
文件 1242 2018-04-20 15:27 mqtt\service\MqttCallBackListener.java
文件 34493 2018-04-20 15:29 mqtt\service\MqttConnection.java
文件 997 2018-04-20 13:24 mqtt\service\MqttDeliveryTokenAndroid.java
文件 15375 2018-04-20 15:29 mqtt\service\MqttService.java
文件 634 2018-04-20 13:24 mqtt\service\MqttServiceBinder.java
文件 2365 2018-04-20 13:24 mqtt\service\MqttServiceConstants.java
文件 4742 2018-04-20 13:24 mqtt\service\MqttTokenAndroid.java
文件 315 2018-04-20 13:24 mqtt\service\MqttTraceHandler.java
文件 1703 2018-04-20 13:24 mqtt\service\ParcelableMqttMessage.java
文件 196 2018-04-20 13:24 mqtt\service\Status.java
- 上一篇:java项目视频教程20套
- 下一篇:JavaEE课程设计
相关资源
- 关于Android的外文文献
- labview与android通信
- android开发范例实战宝典源代码VS视频
- 基于安卓的手机流量监控软件 文献综
- org.eclipse.paho.android.service-1.1.0.jar
- Android手机测试用例
- 内涵FileProvider的android-support-v4包,版
- Android 仿「微信」自定义数字键盘
- Android登录注册服务器_cookieMonster
- unity3D 蓝牙插件 iOS & Android
- android kotlin付费教程视频 免费提供
- Android应用源码之蓝虫火车票余票查询
- Android应用源码之手机实时视频监控项
- android 注入so代码
- nineoldandroids-2.4.0.jar.zip
- Android CoordinatorLayout打造酷炫的顶部栏
- android自定义混淆字典
- android完美电影购票源码
- Android应用案例-《垃圾短信助手案例
- Android 自定义漂亮吐司
- SQlite Android SQLite的应用 简易的学生成
- android人脸识别测试用例
- 百度地图 BaiduLBS_Android.jar
- android studio 编译aidl以及demo
- Android SwitchButton开关
- android ChiceScanGun.rar
- Android Flowlayout:LinearLayout内部控件自动
- android-support-design.jar包 程序文件
- 基于Android平台校园信息发布系统
- android屏幕监视器
评论
共有 条评论