How to Retrieve Webview URL from Firebase Realtime Database in Xamarin.android (c#) ?

CastielTR 141 Reputation points
2021-07-25T13:33:41.17+00:00

How to Retrieve Webview URL from FIrebase Realtime Database in Xamarin.android (c#) ? I can't find any command or any examples for C#, Full of people are use the java but no one use c# android so ı need to help.

This is correctly I need the resource but this solution is write by java, I need the same as but in Xamarin.android(c#).

watch

Link the video: https://www.youtube.com/watch?v=ypRdHO-w8-o&list=PLblLWXxsNTovcxFGQh3D0CnVjsUXBuY8q&index=3

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,348 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,913 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 75,351 Reputation points Microsoft Vendor
    2021-07-26T08:00:33.913+00:00

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

    118481-image.png

    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

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. CastielTR 141 Reputation points
    2021-07-26T09:36:18.987+00:00

    I have a error, the Null expectection, I am already connect the firebase to my project. I dont know why, please check it

    117914-1.png
    118462-image.png
    This is my last day results, today ı have no data.
    117942-3.png


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.