如何使用Firebase动态更改Webview的URL? [英] How to change an URL for webview dynamically using firebase?

查看:26
本文介绍了如何使用Firebase动态更改Webview的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个加载URL(www.google.com)的网络视图.如何更改Webview以从外部加载其他网址,例如在Firebase中编写网址?是否可以?我希望有一个外部更改URL的选项,而不必在活动中更改URL即可重新安装应用程序.

I have an webview which load an URL(www.google.com). How can I change the webview to load an different url externally like by writing the url in firebase? Is it possible? I want an option to change the url externally without having to change the url in the activity an reinstall the app.

推荐答案

那只是侦听存储在Firebase中的url路径,例如

That simply just listen on url path that store in firebase like

private DatabaseReference mUrlReference = FirebaseDatabase.getInstance().getReference().child("url")
ValueEventListener urlListener = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        String url = dataSnapshot.getValue(String.class);
        // Web load here
        webView.loadUrl(url);
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {
        // Getting Url failed, log a message
        Log.w(TAG, "loadUrl:onCancelled", databaseError.toException());
        // ...
    }
};
mUrlReference.addValueEventListener(urlListener);

这篇关于如何使用Firebase动态更改Webview的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆