Issue
I am building an application with webView and Firebase as database, I have implemented both correctly but the problem is that my webView is not retrieving any data from Firebase database and is showing blank when I open application, I have checked the webView by adding URL directly and it shows web page but it does not show anything when I use it with Firebase, please help to sort this thing out.
I am using Android Studio
webView class file:
public class webViewNews extends AppCompatActivity {
private WebView webviewthis;
private RecyclerView webVieRes;
private DatabaseReference mdataRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview_page);
mdataRef = FirebaseDatabase.getInstance().getReference().child("weber");
webviewthis = (WebView)findViewById(R.id.webView_news);
webviewthis.setWebViewClient(new WebViewClient());
webviewthis.getSettings().setJavaScriptEnabled(true);
webviewthis.getSettings().setLoadsImagesAutomatically(true);
mdataRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
post2web webView = dataSnapshot.getValue(post2web.class);
webviewthis.loadUrl(webView);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
webView xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView_news"/>
</LinearLayout>
getter and setter class file:
public class post2web {
private String webViewPost;
public post2web(){
}
public post2web(String webViewPost) {
this.webViewPost = webViewPost;
}
public String getWebViewPost() {
return webViewPost;
}
public void setWebViewPost(String webViewPost) {
this.webViewPost = webViewPost;
}
}
Firebase Database structure for webView
Solution
Your code works. I'm pretty sure that the only problem are the Firebase database rules.
Change your database rules in Firebase and everything will work.
Answered By - Mariano Córdoba
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.