前言:一切以Bmob官方开发文档为准: http://doc.bmob.cn/data/android/develop_doc/ ,新手快速入门: http://doc.bmob.cn/data/android/ 。查看Bmob后台数据是个好习惯
作为只会app客户端,不懂服务端的人,Bmob简直就是救命稻草!用它来存放爬取的数据,朋友圈数据,图片语音视频,还有app版本更新…易如反掌。经常有同学问如何上传头像、文件、图片bla bla,重要的事说三遍:绑定独立域名,绑它,绑它!具体怎么绑问度娘。当然Bmob也提供此类服务,收费,至于价格,还好啦…demo下载:
链接:https://pan.baidu.com/s/1qwQ8AzaLjxUtaqVqDGaNzg
提取码:yrdt
demo基于androidx,AS4.0导入demo无压力。先让app跑起来,再细看代码 。固执使用V4,V7包的同学,自行导包,代码基本一致。官网下个AS 4.0不香么,无需翻墙,速度很快: https://developer.android.google.cn/studio 。安装参考: https://blog.csdn.net/qq_41976613/article/details/91432304
本文除Bmob注册登录,还有沉浸式状态栏、权限申请的方法
特别提醒:使用androidx的同学 ,查看下 gradle.properties文件中 是否包含以下两行,若无则加上:
android.useAndroidX=true
android.enableJetifier=true
一、Bmob SDK 导入
1) 工程目录下的 build.gradle 文件中添加:
maven {url 'https://dl.bintray.com/chaozhouzhang/maven' }
添加后的样子:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {url 'https://dl.bintray.com/chaozhouzhang/maven' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
2) app下 build.gradle 文件中添加:
1)useLibrary 'org.apache.http.legacy'
2)compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
3)implementation 'cn.bmob.android:bmob-sdk:3.7.8'
implementation 'io.reactivex.rxjava2:rxjava:2.2.6'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'com.squareup.okhttp3:okhttp:3.14.1'
implementation 'com.squareup.okio:okio:2.2.2'
implementation 'com.google.code.gson:gson:2.8.5'
添加后的build.gradle文件:
apply plugin: 'com.android.application'
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.asus.bmobtest"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.es