Hello,
Welcome to our Microsoft Q&A platform!
First of all, you need to install following nuget package in your xamarin.android project.
Xamarin.Firebase.Database
Then do not forget to download your google-services.json
file from firebase console, and set the build action
to GoogleServicesJson
Then you can use following code to retrieve Webview URL from Firebase Realtime Database in Xamarin.android
using Firebase.Database;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
WebView webView1 = FindViewById<WebView>(Resource.Id.webView1);
webView1.Settings.JavaScriptEnabled = true;
webView1.SetWebChromeClient(new MyWebChromeClient());
string firebaseURL = "https://fir-databasedemo-xxxxa72.firebaseio.com/";
var mDatabase = FirebaseDatabase.GetInstance(firebaseURL).GetReference("fir-databasedemo-xxxxa72");
DatabaseReference reference = mDatabase.Child("url");
reference.AddValueEventListener(new MyValueChangeLisenter(webView1));
}
internal class MyWebChromeClient : WebChromeClient
{
}
internal class MyValueChangeLisenter : Java.Lang.Object, IValueEventListener
{
private WebView webView1;
public MyValueChangeLisenter(WebView webView1)
{
this.webView1 = webView1;
}
public void OnCancelled(DatabaseError error)
{
// throw new NotImplementedException();
}
public void OnDataChange(DataSnapshot snapshot)
{
// throw new NotImplementedException();
webView1.LoadUrl(snapshot.Value.ToString());
}
}
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our [documentation][4] to enable e-mail notifications if you want to receive the related email notification for this thread. [2]: /api/attachments/117837-image.png?platform=QnA [4]: https://learn.microsoft.com/en-us/answers/articles/67444/email-notifications.html