我有一个简单的google authentification应用程序,我想显示一条欢迎消息.如果电子邮件帐户为j ohnsmith@gmail.com,我想Toast用"欢迎约翰·史密斯!" 我怎样才能做到这一点?
这是我的代码:
if (user == null) {
startActivityForResult(AuthUI.getInstance().createSignInIntentBuilder().build(), SIGN_IN_REQUEST_CODE);
} else {
Toast.makeText(MainActivity.this, "Welcome " + userName, Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud)
我试图使用此代码,但我只获取用户名,而不是名字和姓氏.
AccountManager manager = (AccountManager) getSystemService(ACCOUNT_SERVICE);
Account[] list = manager.getAccounts();
Run Code Online (Sandbox Code Playgroud)
提前致谢!
当我包括:
编译'com.firebaseui:firebase-ui-firestore:3.1.0'
构建失败.firestore版本3.0.0是相同的结果.
没有这个代码,构建就是成功的.
有重复的模块吗?请帮我.
错误:任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败.
java.lang.RuntimeException:java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并dex
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.android"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// firebase
resConfigs "auto"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
// volley
compile 'com.android.volley:volley:1.0.0'
// firebase, map, location
implementation 'com.google.android.gms:play-services-maps:11.4.2'
implementation 'com.google.android.gms:play-services-location:11.4.2'
// firebase storage
compile 'com.google.firebase:firebase-storage:11.4.2'
// …Run Code Online (Sandbox Code Playgroud) 我有一个场景,我需要使用 来创建用户Auth并将更多信息(例如业务名称和类型)添加到 Firestore 数据库。Firestore 作为事务/批处理操作,但仅适用于 Firestore。
有没有一种方法可以执行Auth诸如创建和 Firestore 数据插入之类的操作。两种操作都必须成功或失败。现在我将它们链接起来,但我会担心一个失败而另一个成功需要优雅地处理。
谢谢
java android firebase firebase-authentication google-cloud-firestore
查询作为地图数组的字段的正确方法是什么.
目前的结构是
Collection1
Document1
-papers: <---- This is an array
(0):
-Name:abc
-Id:123
(1):
-Name:xyz
-Id:456
Run Code Online (Sandbox Code Playgroud)
这是我的代码
DocumentReference docRef = db.collection("Collection1").document("Document1");
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document != null && document.exists()) {
//?? how can I retrieve papers
}
}
});
Run Code Online (Sandbox Code Playgroud)
基本上我是检索它并将其转换为ArrayList>然后循环它以创建我的最终ArrayList?
或者它是如何工作的?
我目前正在使用新的 Firestore 作为后端/数据库对 Android 应用程序进行概念验证。我需要通过他们的 id 获取一堆文档(它们都在同一个集合中)
现在,我正在遍历 id 列表并一个一个地获取它们并将它们存储在一个列表中,该列表又更新了应用程序中的 RecycleView。这似乎是很多工作,而且性能不是很好。
从 Firestore 获取文档列表而不必循环所有 id 并一个一个地获取它们的正确方法是什么?
现在我的代码看起来像这样
for (id in ids) {
FirebaseFirestore.getInstance().collection("test_collection").whereEqualTo(FieldPath.documentId(), id)
.get()
.addOnCompleteListener {
if (it.isSuccessful) {
val res = it.result.map { it.toObject(Test::class.java) }.firstOrNull()
if (res != null) {
testList.add(res)
notifyDataSetChanged()
}
} else {
Log.w(TAG, "Error getting documents.", it.exception)
}
}
}
Run Code Online (Sandbox Code Playgroud) 我Collection在 Cloud Firestore 中有一个有一定数量的项目,我们称之为Collection“X”。这个项目的数量将不断变化。在任何给定的时间,我想听听这个项目的数量Collection并whereEqualto()在一个Query基于另一个“集合”对象,我们称之为“Y”:
Query queryStore = FirebaseFirestore.getInstance()
.collection("Y")
.whereEqualTo(USER_ID_LABEL, "item 1 from X")
.whereEqualTo(USER_ID_LABEL, "item 2 from X")
.whereEqualTo(USER_ID_LABEL, "item 3 from X");
//Could be more than 3, could be less than 3, constantly changing
Run Code Online (Sandbox Code Playgroud)
本质上,数量 whereEqualTo()将是动态的。
这种类型的查询可能吗?
我想减少阅读次数,以便从
QuestionCollection(Array of Questions) 中获取问题的详细信息。
我的应用程序就像是 stackoverflow 的一部分。
我想显示一个问题有多少赞、浏览量和评论。所以为了处理这个我创建了多个集合
问题集
评论集
问题点赞
问题视图
问题标签
我认为CommentCollection (comments) 只属于一个问题。所以我正在考虑QuestionCollection像数组或集合一样合并(但它需要另一个读取命中)。哪个更好?
我想totalViews,totalLikes在 QuestionCollection中添加两个变量的( )。但是每次我都必须检查这个问题是否被这个用户喜欢或被这个用户查看。
给我一个建议或替代方案,这样我就可以尽可能少地获取问题详细信息。
编辑
为了显示视图计数, 我迭代并计算QuestionViews 集合,其中 questionID == myQuestionID
为了显示喜欢计数, 我迭代并计算QuestionLikes 集合,其中 questionID == myQuestionID
为什么我不将它添加到 QuestionCollection?因为我想展示最多查看和最喜欢的问题,例如 stackoverflow。如果我将它添加到 QuestionCollection 我怎么知道最喜欢和最多查看的问题。
我想从uploadTask.addOnProgressListenerFirebase 的方法中获取下载网址。如何使用以下代码获取下载网址?
UploadTask uploadTask = storageRef.putBytes(data);
uploadTask.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>()
{
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot)
{
Log.d("aaaaasessin",""+taskSnapshot.getTask().getResult());
}
});
Run Code Online (Sandbox Code Playgroud)
我用过,taskSnapshot.getTask().getResult()但这不起作用。
嗨,我正在使用 Android Studio,但在转换从 Firestore 获得的数据时遇到了麻烦。我将数据保存在 Firestore 类型 GeoPoint 中,我想查询它并转换为 Object 类型LatLng。
这是我的代码:
final FirebaseFirestore db = FirebaseFirestore.getInstance();
final CollectionReference stores = db.collection("stores");
stores.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Log.i(TAG,document.getData().get("position").toString());
}
} else {
Log.w(TAG, "Error getting documents.", task.getException());
}
}
});
Run Code Online (Sandbox Code Playgroud)
这是我得到的
12-16 10:59:21.557 28239-28239/com.company.yummy.yummy I/firebaseCatch: GeoPoint { latitude=29.339555, longitude=169.715858 }
12-16 10:59:21.557 28239-28239/com.company.yummy.yummy I/firebaseCatch: GeoPoint { latitude=68.085393, longitude=-42.081575 }
12-16 10:59:21.557 28239-28239/com.company.yummy.yummy I/firebaseCatch: GeoPoint …Run Code Online (Sandbox Code Playgroud) 我能够从Cloud Firestore数据库中检索数据,但我只是想知道是否仍然可以各种形式显示此数据。例如,条形图还是饼图?