Skip to content
Advertisement

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

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.

Advertisement

Answer

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);
}
}
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement