├── RDT ├── .gitignore ├── .idea │ ├── caches │ │ └── build_file_checksums.ser │ ├── codeStyles │ │ └── Project.xml │ ├── dbnavigator.xml │ ├── dictionaries │ │ └── zhangchaozhou.xml │ ├── externalDependencies.xml │ ├── gradle.xml │ ├── inspectionProfiles │ │ ├── Project_Default.xml │ │ └── profiles_settings.xml │ ├── misc.xml │ └── runConfigurations.xml ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── cn │ │ │ └── bmob │ │ │ └── rdt │ │ │ └── ExampleInstrumentedTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── cn │ │ │ │ └── bmob │ │ │ │ └── rdt │ │ │ │ ├── App.java │ │ │ │ ├── Chat.java │ │ │ │ └── MainActivity.java │ │ └── res │ │ │ ├── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ │ ├── drawable │ │ │ └── ic_launcher_background.xml │ │ │ ├── layout │ │ │ └── activity_main.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ └── test │ │ └── java │ │ └── cn │ │ └── bmob │ │ └── rdt │ │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle └── README.md /RDT/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/libraries 5 | /.idea/modules.xml 6 | /.idea/workspace.xml 7 | .DS_Store 8 | /build 9 | /captures 10 | .externalNativeBuild 11 | -------------------------------------------------------------------------------- /RDT/.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/bmob-android-demo-realtime-data/c635742663f46858aa4d17b748bb7884275acbd7/RDT/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /RDT/.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 21 | 22 | 26 | 27 | 28 | 29 | 39 | 40 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 60 | 61 | 62 | 63 | 64 | 70 | 71 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /RDT/.idea/dbnavigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | -------------------------------------------------------------------------------- /RDT/.idea/dictionaries/zhangchaozhou.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /RDT/.idea/externalDependencies.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /RDT/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /RDT/.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | -------------------------------------------------------------------------------- /RDT/.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /RDT/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 36 | 37 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 86 | 96 | 97 | 98 | 99 | 100 | 101 | 103 | -------------------------------------------------------------------------------- /RDT/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /RDT/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /RDT/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "cn.bmob.rdt" 7 | minSdkVersion 15 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation 'com.android.support:appcompat-v7:28.0.0-rc02' 24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 28 | 29 | /** 30 | * bmob Data SDK 31 | */ 32 | implementation 'cn.bmob.android:bmob-sdk:3.6.6' 33 | } 34 | -------------------------------------------------------------------------------- /RDT/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /RDT/app/src/androidTest/java/cn/bmob/rdt/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package cn.bmob.rdt; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("cn.bmob.rdt", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /RDT/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /RDT/app/src/main/java/cn/bmob/rdt/App.java: -------------------------------------------------------------------------------- 1 | package cn.bmob.rdt; 2 | 3 | import android.app.Application; 4 | 5 | import cn.bmob.v3.Bmob; 6 | 7 | /** 8 | * Created on 18/9/19 09:29 9 | * 10 | * @author zhangchaozhou 11 | */ 12 | public class App extends Application { 13 | @Override 14 | public void onCreate() { 15 | super.onCreate(); 16 | /** 17 | * 数据监听是付费功能,请确保您appkey对应的应用已开通数据监听功能 18 | */ 19 | Bmob.initialize(this, "此处替换你应用的appid"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /RDT/app/src/main/java/cn/bmob/rdt/Chat.java: -------------------------------------------------------------------------------- 1 | package cn.bmob.rdt; 2 | 3 | import cn.bmob.v3.BmobObject; 4 | 5 | /** 6 | * Created on 18/9/19 09:41 7 | * 8 | * @author zhangchaozhou 9 | */ 10 | public class Chat extends BmobObject { 11 | private String name; 12 | private String content; 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public Chat setName(String name) { 19 | this.name = name; 20 | return this; 21 | } 22 | 23 | public String getContent() { 24 | return content; 25 | } 26 | 27 | public Chat setContent(String content) { 28 | this.content = content; 29 | return this; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /RDT/app/src/main/java/cn/bmob/rdt/MainActivity.java: -------------------------------------------------------------------------------- 1 | package cn.bmob.rdt; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.util.Log; 6 | import android.view.View; 7 | import android.widget.Button; 8 | import android.widget.Toast; 9 | 10 | import com.google.gson.Gson; 11 | 12 | import org.json.JSONObject; 13 | 14 | import cn.bmob.v3.BmobRealTimeData; 15 | import cn.bmob.v3.exception.BmobException; 16 | import cn.bmob.v3.listener.SaveListener; 17 | import cn.bmob.v3.listener.ValueEventListener; 18 | 19 | /** 20 | * @author zhangchaozhou 21 | */ 22 | public class MainActivity extends AppCompatActivity implements View.OnClickListener { 23 | 24 | private String TAG = MainActivity.class.getSimpleName(); 25 | 26 | private Button mBtnUpdateChat; 27 | 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setContentView(R.layout.activity_main); 32 | mBtnUpdateChat = findViewById(R.id.btn_update_chat); 33 | mBtnUpdateChat.setOnClickListener(this); 34 | startBmobRealTimeData(); 35 | } 36 | 37 | private void startBmobRealTimeData() { 38 | 39 | final BmobRealTimeData bmobRealTimeData = new BmobRealTimeData(); 40 | bmobRealTimeData.start(new ValueEventListener() { 41 | @Override 42 | public void onConnectCompleted(Exception e) { 43 | if (e == null) { 44 | Log.i(TAG, "连接情况:" + (bmobRealTimeData.isConnected() ? "已连接" : "未连接")); 45 | if (bmobRealTimeData.isConnected()) { 46 | //TODO 如果已连接,设置监听动作为:监听Chat表的更新 47 | bmobRealTimeData.subTableUpdate("Chat"); 48 | } 49 | } else { 50 | Log.e(TAG, "连接出错:" + e.getMessage()); 51 | } 52 | } 53 | 54 | @Override 55 | public void onDataChange(JSONObject jsonObject) { 56 | /** 57 | * {"nameValuePairs":{"appKey":"f25fe6dad5bca9d0bb090072ea1e3c65","tableName":"Chat","objectId":"","action":"updateTable", 58 | * "data":{"nameValuePairs":{"content":"更新Chat表测试+1537324483401","createdAt":"2018-09-19 10:35:00","name":"RDT","objectId":"d5fffe82e9","updatedAt":"2018-09-19 10:35:00"}}}} 59 | */ 60 | Gson gson = new Gson(); 61 | String action = jsonObject.optString("action"); 62 | String jsonString = gson.toJson(jsonObject); 63 | Log.i(TAG, "更新返回内容是:" + jsonString); 64 | Log.i(TAG, "当前更新动作是:" + action); 65 | if (action.equals(BmobRealTimeData.ACTION_UPDATETABLE)) { 66 | //TODO 如果监听表更新 67 | JSONObject data = jsonObject.optJSONObject("data"); 68 | Log.i(TAG, "name:" + data.optString("name")); 69 | Log.i(TAG, "content:" + data.optString("content")); 70 | Toast.makeText(MainActivity.this, "监听到更新:" + data.optString("name") + "-" + data.optString("content"), Toast.LENGTH_SHORT).show(); 71 | } 72 | } 73 | }); 74 | 75 | } 76 | 77 | @Override 78 | public void onClick(View view) { 79 | switch (view.getId()) { 80 | case R.id.btn_update_chat: 81 | Chat chat = new Chat(); 82 | chat.setName("RDT"); 83 | chat.setContent("更新Chat表测试" + System.currentTimeMillis()); 84 | chat.save(new SaveListener() { 85 | @Override 86 | public void done(String objectId, BmobException e) { 87 | if (e == null) { 88 | Log.i(TAG, "新增表数据成功:" + objectId); 89 | Toast.makeText(MainActivity.this, "更新成功", Toast.LENGTH_SHORT).show(); 90 | } else { 91 | Log.e(TAG, "新增表数据出错:" + e.getErrorCode() + "-" + e.getMessage()); 92 | } 93 | } 94 | }); 95 | break; 96 | default: 97 | break; 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /RDT/app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /RDT/app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 11 | 16 | 21 | 26 | 31 | 36 | 41 | 46 | 51 | 56 | 61 | 66 | 71 | 76 | 81 | 86 | 91 | 96 | 101 | 106 | 111 | 116 | 121 | 126 | 131 | 136 | 141 | 146 | 151 | 156 | 161 | 166 | 171 | 172 | -------------------------------------------------------------------------------- /RDT/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 |