【问题标题】:How to get the current Firebase uid from android service?如何从 android 服务获取当前的 Firebase uid?
【发布时间】:2017-01-25 01:48:37
【问题描述】:

我想使用 uid 作为键将当前用户位置推送到 Firebase 我如何从后台服务获取当前用户

public class TrackService extends Service ....{
...........
public void onLocationChanged(Location location) {
    // TODO: insert the new location to the Firebase location childe
    Log.i(TAG, location.toString());

    Log.i(TAG, "onLocationChanged: " + location.toString());


        DatabaseReference key= root.child("Location").child(?USERID?).push();
                key.setValue(location);

}....
}

【问题讨论】:

    标签: android firebase firebase-realtime-database firebase-authentication


    【解决方案1】:

    当前登录的用户始终可以在您应用的任何组件中随时使用FirebaseAuth.getInstance().getCurrentUser()。请注意,如果用户未登录,这可能会返回 null。

    【讨论】:

    • 非常感谢,我不知道我可以在任何地方找到用户
    • 考虑接受这个答案,以便其他用户知道它已经解决
    猜你喜欢
    • 1970-01-01
    • 2020-11-30
    • 2018-04-22
    • 2022-11-11
    • 2021-11-23
    • 2016-09-30
    • 1970-01-01
    • 2016-07-30
    • 1970-01-01
    相关资源
    最近更新 更多