当前位置: 首页 > 知识库问答 >
问题:

FirebaseUI数据库和身份验证

卢树
2023-03-14

我正在尝试制作一个适配器,它将显示给listview实时数据库内容。

带适配器返回null得身份验证:

private void prepareRequests() {
    auth.addAuthStateListener(new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            user = firebaseAuth.getCurrentUser();
            if (user == null) {
                startActivity(new Intent(MainActivity.this, OnStart.class));
                finish();
            } else {
                databaseRef = database.getReference("requests").child(user.getUid());
            }
        }
    });
    FirebaseListAdapter<Request> requestAdapter;
    try {
        requestAdapter = new FirebaseListAdapter<Request>(
                this,
                Request.class,
                android.R.layout.two_line_list_item,
                databaseRef) {
            @Override
            protected void populateView(View v, Request model, int position) {
                ((TextView) v.findViewById(R.id.requestName)).setText(model.getRequestName());
                ((TextView) v.findViewById(R.id.handled)).setText(model.getHandled());
            }
        };

    } catch (NullPointerException e){
        Request request = new Request("Make new request here!", "false", "no one", "None", 0, 0, "No Message");
        databaseRef.child("Request").setValue(request);
        requestAdapter = new FirebaseListAdapter<Request>(
                this,
                Request.class,
                android.R.layout.two_line_list_item,
                databaseRef
        ) {
            @Override
            protected void populateView(View v, Request model, int position) {
                ((TextView) v.findViewById(R.id.requestName)).setText(model.getRequestName());
                ((TextView) v.findViewById(R.id.handled)).setText(model.getHandled());
            }
        };
    }

    ListView listView = (ListView) findViewById(R.id.list_of_req);
    listView.setAdapter(requestAdapter);
}

类:

public class Request {
    private String requestname;
    private String handled;
    private String type;
    private String handler;
    private String message;
    private double lat;
    private double longt;

    public Request() {
    }

    public Request(String requestname, String handled, String handler, String type, double lat, double longt, String message) {
        this.requestname = requestname;
        this.handled = handled;
        this.lat = lat;
        this.longt = longt;
        this.type = type;
        this.handler = handler;
        this.message = message;
    }

    public String getRequestName(){
        return requestname;
    }

    public void setRequestName(String requestname){
        this.requestname = requestname;
    }

    public double getLat () {
        return lat;
    }

    public void setLat(double lat) {
        this.lat = lat;
    }

    public double getLongt() {
        return longt;
    }

    public void setLongt(double longt) {
        this.longt = longt;
    }

    public String getHandled() {
        return handled;
    }

    public void setHandled(String handled){
        this.handled = handled;
    }

    public String getType(){
        return type;
    }

    public void setType (String type) {
        this.type = type;
    }

    public String getHandler() {
        return handler;
    }

    public void setHandler(String handler){
        this.handler = handler;
    }

    public String getMessage(){
        return message;
    }

    public void setMessage(String message){
        this.message = message;
    }
}

请求布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/requestName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/colorPrimary"
        android:textSize="18sp" />

    <TextView
        android:id="@+id/handled"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="16sp" />
</LinearLayout>

共有1个答案

闻人凯泽
2023-03-14

我发现了问题,Android是异步的,这意味着它不需要等待身份验证状态监听器,而是直接跳入数据库分析。

我所要做的就是将数据库和列表适配器放在侦听器内部。

 类似资料:
  • 我已经开始开发一个由Google的Firebase服务提供支持的应用程序。我很好奇数据传输在Auth和数据库服务中是否安全。如果没有,我是否可以阅读任何材料来源以实现加密? 非常感谢。

  • 在android studio 3.1.3中,用于链接firebase身份验证的“implementation'com.google.firebase:firebase-auth:11.6.0'”和用于链接firebase数据库的“implementation'com.google.firebase:firebase-database:11.8.0'”是app level Gradle中提供的默认

  • 继续我先前的问题。我正在研究CAS 5,以便根据需要进行修改。在CAS教程的帮助下,我现在已经完成了自定义身份验证。现在,我向pom添加了以下依赖项。xml,通过以下链接连接到数据库。 并在应用程序中添加了数据库身份验证属性。属性 但这不起作用意味着 类型org.apereo.cas.configuration.model.support.jdbc.QueryJdbcAuthentiationPr

  • 我目前正在使用FirebaseAuth和web小部件库firebaseui web开发基于VueJS的登录流原型。 成功认证后(无论是< code>password还是< code>google provider ),小部件加载栏会不断重复,firebaseui-web不会触发其< code > signinseccesswithauthresult 回调。但是对< code > identity

  • 我为我的web页面和web服务实现了数据库身份验证。这两者都很好,现在我必须添加Ldap身份验证。我必须通过远程Ldap服务器(使用用户名和密码)进行身份验证,如果用户存在,我必须使用我的数据库作为用户角色(在我的数据库中,用户名是相同的Ldap用户名)。因此我必须从实际代码切换到上面解释的Ldap和数据库身份验证。我的代码是:SecurityConfig类 MyUserDetailsServic

  • 问题内容: 确保GWT + Tomcat应用程序执行身份验证和授权的最佳策略是什么? 问题答案: 有两种基本策略: 确保入口点; 保护远程服务。 最简单的方法是使用常规的Web应用程序安全工具来限制对GWT生成的html / js文件的访问: 春季安全; web.xml约束。 这样可以让您拥有eg 和。 保护远程服务 如果上述解决方案还不够,您可以进行更深入的研究。我已经通过Spring Secu