第一步:https://leancloud.cn/docs/rest_api.html#获取对象
先查看该文档清楚请求的格式 比如header里都需要什么参数 严格按照
第二步:https://leancloud.cn/dashboard/apionline/index.html#!/classes/查询对象_get_3
清楚自己客户端绑定的url及返回的参数:
第三步:创建对应的app一些对应的参数
第四步:创建对应的表:创建表的时候注意ACL权限(重点)可读模式
第五步:代码示例:读取时候切记有的是response.body().toString();可读取内容
有的是response.body().string();;可读取内容
private static final
String
URL
=
"https://leancloud.cn:443/1.1/classes/devices/58d0e2f244d90400684d26e4"
;
private static final
String
APP_ID
=
"onXRojJheCxxxxxx-gzGzoHsz"
;
private static final
String
APP_KEY
=
"SUB7qOw1qQvxxxxxxx"
;
public static void
checkRegiste
(
final
Activity mainActivity) {
if
(
okHttpClient
==
null
) {
OkHttpClient.Builder builder =
new
OkHttpClient.Builder()
;
okHttpClient
= builder.build()
;
}
Request.Builder resBuilder =
new
Request.Builder()
;
resBuilder.addHeader(
"X-LC-Id"
,
APP_ID
)
;
resBuilder.addHeader(
"X-LC-Key"
,
APP_KEY
)
;
// resBuilder.addHeader("Content-Type", "application/json");
resBuilder.url(
URL
// + "devices?where=" + URLEncoder.encode("{\"open\":\"" + true + "\"}")
)
;
okHttpClient
.newCall(resBuilder.build()).enqueue(
new
Callback() {
@Override
public void
onResponse
(Call call
, final
Response response)
throws
IOException {
new
Handler(Looper.
getMainLooper
()).post(
new
Runnable() {
@Override
public void
run
() {
try
{
JSONObject data =
new
JSONObject(
response
.body().string())
;
if
(data.optBoolean(
"to_death"
)) {
mainActivity
.finish()
;
return;
}
}
catch
(Exception e) {
e.printStackTrace()
;
}
}
})
;
}
@Override
public void
onFailure
(Call call
,
IOException e) {
e.printStackTrace()
;
}
})
;
}