我可以将数据升级到Firebase,所以连接起来,我认为连接没有问题 但我无法从Firestore检索数据。
依赖项:
implementation 'com.google.firebase:firebase-messaging:11.6.2'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-firestore:17.0.4'
implementation 'com.google.firebase:firebase-database:16.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
implementation 'com.google.api-client:google-api-client:1.25.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.material:material:1.0.0'
implementation "com.facebook.android:facebook-android-sdk:4.35.0"
代码:
private TextView showusername;
private TextView showpassword;
private TextView showphone;
private FirebaseFirestore db = FirebaseFirestore.getInstance();
private CollectionReference memRef = db.collection("Member");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_personal);
showusername = (TextView) findViewById(R.id.username);
showpassword = (TextView) findViewById(R.id.password);
showphone = (TextView) findViewById(R.id.phone);
}
@Override
protected void onStart() {
super.onStart();
memRef.whereEqualTo("name","王小名")
.get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
for (QueryDocumentSnapshot documentSnapshot : queryDocumentSnapshots){
Member mem = documentSnapshot.toObject(Member.class);
String name = mem.getName();
String password = mem.getPassword();
String phone = mem.getPhone();
showusername.setText(name);
showpassword.setText(password);
showphone.setText(phone);
}
}
});
}
logcat:
2020-02-24 14:32:08.625 3747-3840 /? E / FirebaseInstanceId:令牌检索失败:INVALID_SENDER
我只是添加
implementation 'com.google.firebase:firebase-messaging:20.1.0'
进入我的依赖关系
但是在先同步然后显示节目时失败
ERROR: Manifest merger failed : uses-sdk:minSdkVersion 15 cannot be smaller than version 16 declared in library [com.google.firebase:firebase-messaging:20.1.0] C:\Users\jack0\.gradle\caches\transforms-2\files-2.1\e40595c3c511248facbf0e003354fb90\jetified-firebase-messaging-20.1.0\AndroidManifest.xml as the library might be using APIs not available in 15
Suggestion: use a compatible library with a minSdk of at most 15,
or increase this project's minSdk version to at least 16,
or use tools:overrideLibrary="com.google.firebase.messaging" to force usage (may lead to runtime failures)