WebView on android shows HTML

1

I'm developing an android app, I use a webservice to pick up news from a website and play pro app. This news comes in HTML and I get a webview and I get the HTML for it, and it works perfectly at the API's level > = 19. I'm using wbConteudo.loadDataWithBaseURL("file:///android_asset/",noticia.getConteudo(),"text/html; charset=utf-8", "utf-8",null); to set data in the webview, as there are news that are fixed and I decided to leave the photos in the "asset" folder of the android and then load them along with the HTML content.

But when I use an api level < 19, the webview shows me the pure HTML code for the user instead of the formatted one ("test"), I'd like to know what's happening, since I need to work on the API level below 19.

Ex:

I'vedoneatesthere,andusingwbConteudo.loadData(noticia.getConteudo(),"text/html; charset=utf-8", "utf-8"); and it worked the HTML content, but the internal photos that are in the asset folder do not work since I'm not using wbConteudo.loadDataWithBaseURL("file:///android_asset/",noticia.getConteudo(),"text/html; charset=utf-8", "utf-8",null);

So I'd like to know what's going on and why it's occurring and a possible solution.

Screen Code:

public class NoticiaFragment extends Fragment {
private Noticia noticia;
public static Integer aba;

public NoticiaFragment(){

}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle bundle = getArguments();
    noticia = new Noticia(bundle.getString("titulo"), bundle.getString("conteudo"));
    NoticiaFragment.aba = bundle.getInt("ABA");
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_noticia,null);
    TextView txTitulo = (TextView) view.findViewById(R.id.txTitulo);
    WebView wbConteudo = (WebView) view.findViewById(R.id.wbConteudo);
    txTitulo.setText(noticia.getTitulo());
    wbConteudo.loadDataWithBaseURL("file:///android_asset/",noticia.getConteudo(),"text/html; charset=utf-8", "utf-8",null);//Isso funciona perfeitamente API >= 19
    //wbConteudo.loadData(noticia.getConteudo(),"text/html; charset=utf-8", "utf-8");//Isso funciona em API < 19
    wbConteudo.setBackgroundColor(Color.TRANSPARENT);

    return view;
}

public static int getAba() {
    return aba;
}

public static void setAba(int aba) {
    NoticiaFragment.aba = aba;
}

}

Layout Code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment_noticia"
>

<TextView
    android:text="Titulo"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/txTitulo"
    android:layout_marginTop="16dp"
    android:layout_marginBottom="16dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:textAppearance="@style/tituloNoticia"
    android:gravity="center"/>

<WebView
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:id="@+id/wbConteudo" /></LinearLayout>

Grade:

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "24.0.2"
defaultConfig {
    applicationId "br.com.patrick.fetiep"
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:support-v4:25.0.1'
compile 'com.android.support:design:25.0.1'

compile 'org.jetbrains:annotations-java5:15.0'

compile files('libs/activation.jar')
compile files('libs/additionnal.jar')
compile files('libs/mail.jar')
compile files('libs/gson-2.2.4-sources.jar')
compile files('libs/org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar')
compile files('libs/picasso-2.5.2.jar')

}

    
asked by anonymous 16.11.2016 / 17:24

1 answer

0

Dude, it's going to be really hard for someone to come here and tell you exactly where your error is ... All I can tell you is to be careful about the version you're using to develop.

The official website of Developer.Android already "recommends using the API version 19+." What I can tell you is that only a low percentage of people use versions prior to that.

You can check here for the versions that are currently being used most. And if you're unsure which methods are still working on this version change, you can check on this other link .

I hope I have helped!

    
16.11.2016 / 18:47