Android Studio MQTT功能

本文介绍了在Android Studio 3.0.1版本中如何集成MQTT功能,包括修改build.gradle文件,设置AndroidManifest.xml权限,注册服务以及编写MQTT连接和消息收发的逻辑代码。该实现可在Android 8.0系统上运行,作者计划后续添加更多功能,如控制硬件设备和集成百度语音控制。
摘要由CSDN通过智能技术生成

使用的Android Studio版本为3.0.1,没办法,升级到3.2.1后弄不出来了,又下了个3.0的绿色版,反正自己用又不考虑用户感受啥的,能实现我想要的功能能在我手机上跑就OK。
首先是APP下build.grdle文件:

apply plugin: 'com.android.application'

android {
   
    compileSdkVersion 25
    buildToolsVersion '26.0.2'
    defaultConfig {
   
        applicationId "com.example.administrator.kongzhiqi"
        minSdkVersion 10
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
   
        release {
   
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
   
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
   
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'
    compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
    compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.1'
    compile 'io.reactivex:rxjava:1.1.0'
    compile 'io.reactivex:rxandroid:1.1.0'
    compile 'com.orhanobut:logger:2.1.1'
    compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
    testCompile 'junit:junit:4.12'
}

然后是项目下的build.grdle文件

buildscript {
   
    repositories {
   
        jcenter()
        maven {
   
            url "https://repo.eclipse.org/content/repositories/paho-releases/"
        }
    }
    dependencies {
   
        classpath 'com.android.tools.build:gradle:3.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
   
    repositories {
   
        jcenter()
    }
}

task clean(type: Delete)<
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值