小编Ros*_*des的帖子

如何用空格来整个句子

我试过了:

    char tab[200];
    cin>>tab;
    cout<<tab<<endl;
Run Code Online (Sandbox Code Playgroud)

即使我在控制台中输入A B C所有3个字符和空格,我也想做到这一点tab.

c++ cin char

1
推荐指数
2
解决办法
2万
查看次数

Firestore 安全规则允许用户访问他们的数据

我想写一个这样的规则:

service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userId}/{document=**} {
      allow read, write: if request.auth.uid == userId;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

也就是说,如果该用户是经过身份验证的用户,我希望允许对该用户的所有数据进行所有读写操作。

不幸的是,这不起作用。我收到一条错误消息,指出我无权访问数据。

firebase firebase-security google-cloud-firestore

1
推荐指数
1
解决办法
3256
查看次数

从Firebase(android)获取数据时,如何避免代码重复?

我想这个问题将适用于使用异步调用的任何应用程序。

我对这一切还比较陌生,而我遇到的问题是从Firebase到我的Android应用程序中获取数据。

在整个应用程序中,有几个类需要使用数据库中“用户”表中的数据,我可以从中获得以下数据:

DatabaseReference reference = FirebaseDatabase.getInstance().getReference()
.child("users").child("exampleDataFromUsers");
reference.addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        // do something with the snapshot
    }
Run Code Online (Sandbox Code Playgroud)

我想创建一个通用类来处理从Firebase检索的数据,例如:

public class FirebaseDataHandler() {

  static String getUserReports() {
    // get Reports
  }

  static int getUserAge() {
    // get age
  }
}
Run Code Online (Sandbox Code Playgroud)

但是由于它是异步检索的,因此对这些方法的任何调用都只会返回null。结果,我的代码当前到处都是重复的代码。

如果有人对实现此目标的更好方法有任何见识,将不胜感激。谢谢。

java android asynchronous firebase firebase-realtime-database

0
推荐指数
1
解决办法
162
查看次数

Firestore 自定义索引不起作用

在我的 firestore 数据库中,我有一个名为 的集合states,我已手动添加stateIdstateName到索引中。当我尝试使用云函数访问集合时,它报告崩溃,指出查询需要索引并显示/生成添加索引的链接。但是当我复制粘贴链接时,它没有显示stateName在索引字段中,我基于 进行排序stateName。这是手动索引集合的屏幕截图

在此输入图像描述

这是我获取州列表的代码

exports.getStates = functions.https.onRequest((request, response)=>{
    const db = admin.firEDIT !estore();
    const countryId = request.body['countryId'];
    return db.collection("states").where("countryId","==",countryId).where("isDeleted","==","0")
    .select("stateId","stateName").orderBy("stateName")
    .get().then(snapshot=>{
        const states =[];
        snapshot.docs.forEach(doc=>{
            states.push(doc.data());
        });
        return response.status(200).json(states);
    });
});
Run Code Online (Sandbox Code Playgroud)

这是 firebase 控制台日志中显示的错误

Error: The query requires an index. You can create it here: https://console.firebase.google.com/project/functionstest-54bd9/database/firestore/indexes?create_index=EglkaXN0cmljdHMaDQoJaXNEZWxldGVkEAIaCwoHc3RhdGVJZBACGhAKDGRpc3RyaWN0TmFtZRACGgwKCF9fbmFtZV9fEAI
    at ClientReadableStream._emitStatusIfDone (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:255:19)
    at ClientReadableStream._receiveStatus (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:233:8)
    at /user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:705:12
Run Code Online (Sandbox Code Playgroud)

我的代码有什么问题吗?如何根据stateName工作进行订购?

更新1

我使用了 firebase 控制台日志中提供的链接,然后该链接stateName也列在索引字段中,并且该集合现在已编入索引并且正在按预期工作。这是我的疑问

  1. 为什么第一次不显示stateName,第二次才显示?
  2. 为什么手动索引不起作用?

firebase google-cloud-firestore

0
推荐指数
1
解决办法
2643
查看次数

Chrome 自定义选项卡在 Chrome 中作为新选项卡打开,而不是在应用程序内打开,为什么?

如何在不打开后台 Google Chrome 的情况下在应用程序中打开自定义选项卡...

这是我的代码

String a="http://www.gpamravati.ac.in/gpamravati";
        CustomTabsIntent.Builder builder=new CustomTabsIntent.Builder();
        CustomTabsIntent custom=builder.build();
        custom.intent.setPackage("com.android.chrome");
        builder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary));
        custom.launchUrl(this, Uri.parse(a));
Run Code Online (Sandbox Code Playgroud)

当我单击网站菜单项时,它会调用 chrome 自定义选项卡

打开是这样的

java android android-customtabs

-1
推荐指数
1
解决办法
2203
查看次数