I have many HTML files in assets folder and I use jQuery mobile to show them in Android mobiles.I know it's little hard to answer this without any my code, but until now I didn't find a usable code to check it in Android studio, therefore I need it from you guys. Example, I have HTML files in assets folder, how can I convert it to plain text and share it via WhatsApp? There is code below, under example pictures, as I know Html.fromhtml
can do this and and RegEx to remove HTML tags .toString().replaceAll("\<.*?>", ""));
But I don't know how to realise it.
I know only something like this code can do it
public class MainActivity extends AppCompatActivity {
WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setDisplayZoomControls(false);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("file:///android_asset/about.html");
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (item.getItemId())
{
case R.id.sharecontent:
Share ();
return true;
}
return super.onOptionsItemSelected(item);
}
public void Share() {
this.Share(Html.fromHtml(this.web.getContent()).toString().replaceAll("\\<.*?>", ""));
}
public String getContent() {
return this.m.ReadFile(GetUrl().substring(GetUrl().indexOf("asset/") + 6));
}
}
Example of HTML file in emulator
(30.09.2017) I didn't get it work yet because I need access to HTML files inside subfolders. I read this, but still didn't understand - List of files in assets folder and its subfolders
Muhammad Tufail's answer works for only 1 HTML.