Git Product home page Git Product logo

androidsdk's Introduction

OneNET RESTful SDK for Android

Download License

本项目是 中移物联网公司 为方便Android开发者接入 OneNET 平台而开发的客户端SDK。关于 OneNET 请进入 OneNET门户 了解详情。

系统要求

  • SDK运行要求:Android 1.6 (API 4) 及以上
  • Sample运行要求:Android 4.1 (API 16) 及以上

使用方法

dependencies {
    implementation 'com.chinamobile.iot.onenet:onenet-sdk:2.2.1'
}

详细说明请参考 wiki 文档

示例

v2.0版本提供了更加美观和丰富的示例App供开发者参考,遵循Google Material Design风格,完全开源,开发者可以Clone项目源码查看详细内容。

也可以在此 下载安装包

使用的第三方库

SDK

Sample App

说明

  • v2.0 版本完全重写了 SDK,传输层使用 OkHttp3,API根据 OneNET RESTful 文档 做了相应的增减,API 与 v1.x 不兼容,请使用了 v1.x 版本的开发者慎重升级。
  • 更新到 v2.x 的开发者,如果要查看 v1.x 的代码,只要 git checkout OneNETSDK-v1 即可,或 在此查看

反馈及意见

SDK 使用过程中遇到的任何问题,都可以通过 Issues 来反馈,请尽可能的描述清楚遇到的问题,如果有错误信息也一同附带,并且在 Labels 中指明类型为 bug 或者其他,我们会以最快的速度给予解决。

通过这里查看已有的 Issues 和提交 Bug

License

The MIT License (MIT)

Copyright (c) 2015-2018 China Mobile IOT

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

androidsdk's People

Contributors

chenglei1986 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

androidsdk's Issues

同时导入Bmob和OnenetAPI报重复导包问题

如题 我在工程中集成了Bmob和Onenet,都有okhttp3,所以按照您上面说的exclude掉了okhttp3的两个包,但是打包运行就会在OneNetApi.init(getApplication(),false);报错。
java.lang.NoClassDefFoundError: Failed resolution of: Lokhttp3/Interceptor;
at com.chinamobile.iot.onenet.OneNetApi.init(OneNetApi.java:69)

Caused by: java.lang.ClassNotFoundException: Didn't find class "okhttp3.Interceptor" on path: DexPathList[[zip file等等

获取datapoint的查询url错误

在 DataPoint.class 中,查询的url路径最后漏掉了datapoints,导致调用OneNetApi.queryDataPoints接口时,会出错。
public static String urlForQuerying(String deviceId, Map<String, String> params) { HttpUrl.Builder builder = new HttpUrl.Builder().scheme(Urls.SCHEME).host(Urls.sHost) .addPathSegment("devices").addPathSegment(deviceId);

Android studio如何集成sdk?

按照wiki的教程来报错Project with path ':onenet-sdk' could not be found in project ':app',sdk是直接拷到项目的总目录下吗,compile project(':onenet-sdk')和compile 'com.chinamobile.iot.onenet:onenet-sdk:+'这两句分别要写在哪个build.gradle中?

无网络状态下发送命令崩溃

E/chenglei: retried 1 times
E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
Process: com.wiseworld.simple, PID: 11643
java.util.NoSuchElementException
at okhttp3.internal.connection.RouteSelector.next(RouteSelector.java:75)
at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.java:187)
at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.java:107)
at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.java:87)
at okhttp3.internal.connection.Transmitter.newExchange(Transmitter.java:162)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:41)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
at com.chinamobile.iot.onenet.http.RetryInterceptor.process(RetryInterceptor.java:32)
at com.chinamobile.iot.onenet.http.RetryInterceptor.process(RetryInterceptor.java:44)
at com.chinamobile.iot.onenet.http.RetryInterceptor.intercept(RetryInterceptor.java:25)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
at com.chinamobile.iot.onenet.OneNetApi$1.intercept(OneNetApi.java:118)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:221)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:172)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:784)

demo运行不了

demo运行不了,手机魅族魅蓝5s
Process: com.chinamobile.iot.onenet.sdksample, PID: 30332
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.text.Layout.getLineForOffset(int)' on a null object reference
at android.widget.Editor.updateCursorPositionMz(Editor.java:6986)
at android.widget.Editor.updateCursorsPositions(Editor.java:1766)
at android.widget.TextView.getUpdatedHighlightPath(TextView.java:5703)
at android.widget.TextView.onDraw(TextView.java:5896)
at android.view.View.draw(View.java:16539)
at android.view.View.updateDisplayListIfDirty(View.java:15492)
at android.view.View.draw(View.java:16293)
at android.view.ViewGroup.drawChild(ViewGroup.java:3735)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3525)
at android.view.View.updateDisplayListIfDirty(View.java:15484)
at android.view.View.draw(View.java:16293)
at android.view.ViewGroup.drawChild(ViewGroup.java:3735)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3525)
at android.view.View.draw(View.java:16551)
at android.support.design.widget.TextInputLayout.draw(TextInputLayout.java:1577)
at android.view.View.updateDisplayListIfDirty(View.java:15492)
at android.view.View.draw(View.java:16293)
at android.view.ViewGroup.drawChild(ViewGroup.java:3735)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3525)
at android.view.View.updateDisplayListIfDirty(View.java:15484)
at android.view.View.draw(View.java:16293)
at android.view.ViewGroup.drawChild(ViewGroup.java:3735)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3525)
at android.view.View.updateDisplayListIfDirty(View.java:15484)
at android.view.View.draw(View.java:16293)
at android.view.ViewGroup.drawChild(ViewGroup.java:3735)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3525)
at android.view.View.updateDisplayListIfDirty(View.java:15484)
at android.view.View.draw(View.java:16293)
at android.view.ViewGroup.drawChild(ViewGroup.java:3735)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3525)
at android.view.View.updateDisplayListIfDirty(View.java:15484)
at android.view.View.draw(View.java:16293)
at android.view.ViewGroup.drawChild(ViewGroup.java:3735)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3525)
at android.view.View.updateDisplayListIfDirty(View.java:15484)
at android.view.View.draw(View.java:16293)
at android.view.ViewGroup.drawChild(ViewGroup.java:3735)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3525)
at com.android.internal.policy.PhoneWindow$DecorView.dispatchDraw(PhoneWindow.java:2839)
at android.view.View.draw(View.java:16551)
at com.android.internal.policy.PhoneWindow$DecorView.draw(PhoneWindow.java:2820)
at android.view.View.updateDisplayListIfDirty(View.java:15492)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:286)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:292)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:327)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:3056)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2860)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2469)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1342)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6824)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:896)
at android.view.Choreographer.doCallbacks(Choreographer.java:698)
at android.view.Choreographer.doFrame(Choreographer.java:633)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:882)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:6009)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:840)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:730)

Unable to change port

hi i need to use this on my local country hosted onenet plateform , i am unable to change port to some costum port, can anybody help me out

竟然没有超时设置,默认只有10秒!10秒真男人啊,兄弟,你是认真的吗?

/**
* 初始化SDK(for HTTPS)
*
* @param application Application实例
* @param debug 是否开启调试模式(打印HTTP请求和响应日志)
* @param cerString 证书rfc样式输出的字符串
*/
public static void init(Application application, boolean debug, String cerString) {
try {
sAppKey = Meta.readAppKey(application);
Urls.sScheme = Meta.readScheme(application);
Urls.sHost = Meta.readHost(application);
} catch (Exception e) {
e.printStackTrace();
}

    sDebug = debug;

    OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder()
            ;
    if (sDebug) {
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new OneNetLogger());
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        okHttpClientBuilder.addNetworkInterceptor(loggingInterceptor);
    }
    okHttpClientBuilder.addInterceptor(sApiKeyInterceptor);

    if (!TextUtils.isEmpty(cerString)) {
        try {
            CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
            Collection<? extends Certificate> certificates = certificateFactory.generateCertificates(new Buffer().writeUtf8(cerString).inputStream());
            if (null == certificates || certificates.isEmpty()) {
                throw new IllegalArgumentException("expected non-empty set of trusted certificates");
            }

            char[] password = "password".toCharArray();
            KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
            keyStore.load(null, password);

            int index = 0;
            for (Certificate certificate : certificates) {
                String certificateAlias = Integer.toString(index++);
                keyStore.setCertificateEntry(certificateAlias, certificate);
            }

            KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
            keyManagerFactory.init(keyStore, password);
            TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
            trustManagerFactory.init(keyStore);
            TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
            if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
                throw new IllegalStateException("Unexpected default trust managers:" + Arrays.toString(trustManagers));
            }

            SSLContext sslContext = SSLContext.getInstance("TLS");
            sslContext.init(null, trustManagers, null);
            SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();

            okHttpClientBuilder.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustManagers[0]);
        } catch (CertificateException e) {
            e.printStackTrace();
        } catch (KeyStoreException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (UnrecoverableKeyException e) {
            e.printStackTrace();
        } catch (KeyManagementException e) {
            e.printStackTrace();
        }
    }

    sHttpExecutor = new HttpExecutor(okHttpClientBuilder.build());
}

/**
* Sets the default connect timeout for new connections. A value of 0 means no timeout,
* otherwise values must be between 1 and {@link Integer#MAX_VALUE} when converted to
* milliseconds.
*
*

The connectTimeout is applied when connecting a TCP socket to the target host.
* The default value is 10 seconds.
*/
public Builder connectTimeout(long timeout, TimeUnit unit) {
connectTimeout = checkDuration("timeout", timeout, unit);
return this;
}

Android Studio 2.1.2 open this project have some problem.

I clone this project,use Android Studio 2.1.2 to open.On the Messages Gradle Sync windows,show the below message:
Error:Gradle version 2.2 is required. Current version is 2.10. If using the gradle wrapper, try editing the distributionUrl in C:\Users\lxy\Desktop\AndroidSDK-master\gradle\wrapper\gradle-wrapper.properties to gradle-2.2-all.zip.

Please fix the project's Gradle settings.
Fix Gradle wrapper and re-import project
Gradle settings

怎么下载?

可以下载吗,我点击了下载按钮没有相应啊?

AddDataStreamActivity.java

AddDataStreamActivity.java文件中多处报错。没有找到 public class AddDataStreamActivity类。
(初学者,第一次用AS),引用AddDataStreamActivity类的地方也报错。
下面是该文件中开始报错的部分(下面还有好多,不一一列出):
24 public class import android.app.Activity;
25 import android.content.pm.PackageManager;
26 import android.support.annotation.NonNull;
27 import android.support.v4.app.ActivityCompat;
请问如何解决这些问题,谢谢!

demo error

I/OneNetApi: {"errno":3,"error":"auth failed"}

api-key is copy from onenet ,but why???

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.