Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I want to show my externalurl link coming from api in webview in my application

My Code :

My Adapter

@Override
    public void onBindViewHolder(@NonNull SliderAdapter.SliderHolder holder, int position) {
        final HomePage.ContentList item = homePageList.get(position);
          SliderHolder viewHolder = (SliderHolder) holder;
          viewHolder.txt_category.setText(item.getCategoryName());
          viewHolder.title_item_list_pager.setText(item.getTitle());
          if (item.getImage() != null)
              Glide.with(holder.itemView).load(item.getImage()).into(viewHolder.img);
          Log.d("TEST103-2", "PV");
          viewHolder.img.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent intent = new Intent(v.getContext(), NewsDetail.class);
                  intent.putExtra("newsdetail",homePageList.get(position).getExternalUrl());
                  v.getContext().startActivity(intent);
                  }
          });

     }

news detail class

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

package com.platin.android;

import android.os.Bundle;
import android.webkit.WebView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class NewsDetail extends AppCompatActivity {

    WebView newsdetail;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.news_detail);

        newsdetail = findViewById(R.id.newsdetail);
        newsdetail.getSettings().setJavaScriptEnabled(true);
        newsdetail.loadUrl(getIntent().getStringExtra("newsdetail"));

    }
}

I want to show my externalurl link coming from api in webview in my application.
When I click for detail, it opens on google chrome. but I want it to show in application.

>Solution :

set setWebViewClient in your WebView also you can enable javaScript

webView.loadUrl(getIntent().getStringExtra(LINK));
webView.setWebViewClient(new MyWebViewClient());
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);

and Clint is:

private class MyWebViewClient extends WebViewClient {

@Override
public void onPageFinished(WebView view, String url) {
    super.onPageFinished(view, url);
}
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading