I want to add webView in Firebase so that if i have to change the webpage URL of that webView , i can simply add a new URL in firebase Database and it changes the webView accordingly
I have searched everywhere but didnt get helpful answer, is it possible with firebase to do so?
Update:
Actually I am trying to build a news app, where users can click on web link of the news and it will take them to that respective web page of in-app web browser, I don't think remote-config will be helpful in this purpose.
I'm using Android Studio.
Firebase Java Class File
public class webViewNews extends AppCompatActivity {
private RecyclerView webRecycle;
private DatabaseReference mDatabaseReference;
private WebView webviewthis;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview_page);
mDatabaseReference = FirebaseDatabase.getInstance().getReference().child("play");
webviewthis = (WebView) findViewById(R.id.webView_news);
webRecycle = (RecyclerView) findViewById(R.id.webViewList);
webviewthis.getSettings().setJavaScriptEnabled(true);
webviewthis.getSettings().setLoadsImagesAutomatically(true);
webviewthis.loadUrl(mDatabaseReference.toString());
}
@Override
protected void onStart() {
super.onStart();
FirebaseRecyclerAdapter<post, webViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<post, webViewHolder>(
post.class,
R.layout.webview_card,
webViewHolder.class,
mDatabaseReference
) {
@Override
protected void populateViewHolder(webViewHolder viewHolder, post model, int position) {
viewHolder.setWebViewPost( model.getWebViewPost());
}
};
webRecycle.setAdapter(firebaseRecyclerAdapter);
}
public static class webViewHolder extends RecyclerViewPager.ViewHolder {
View mView;
public webViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setWebViewPost( final String webViewPost) {
WebView WebViewPost = (WebView)mView.findViewById(R.id.webView_news);
WebViewPost.loadUrl(webViewPost);
}
}
}
Post Class File
public class postClass {
private String titleName, DescriptionName, Picture,webViewPost;
public post(String webViewPost) {
this.webViewPost = webViewPost;
}
public postClass(){
}
public postClass(String TitleName, String descriptionName, String Picture) {
this.titleName = TitleName;
this.DescriptionName = descriptionName;
this.Picture = picture;
}
public String gettitleName() {
return titleName;
}
public void setTitleName(String TitleName) {
this.titleName = TitleName;
}
public String getDescriptionName() {
return DescriptionName;
}
public void setDescriptionName(String descriptionName) {
this.DescriptionName = descriptionName;
}
public String getPicture() {
return Picture;
}
public void setPicture(String picture) {
this.Picture= picture;
}
public String getWebViewPost() {
return webViewPost;
}
public void setWebViewPost(String webViewPost) {
this.webViewPost = webViewPost;
}
}
Crash report
java.lang.RuntimeException: Unable to start activity ComponentInfo{hello.yellow/hello.yellow.webViewNews}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.webkit.WebSettings android.webkit.WebView.getSettings()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.webkit.WebSettings android.webkit.WebView.getSettings()' on a null object reference
at hello.yellow.webViewNews.onCreate(webViewNews.java:29)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)