sagar shetty
sagar shetty

Reputation: 41

How to change an URL for webview dynamically using firebase?

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.

Upvotes: 0

Views: 561

Answers (1)

JustKhit
JustKhit

Reputation: 407

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);

Upvotes: 2

Related Questions