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')
}