Im trying load this file into my webview but its not loading
file path is something like
- /data/user/0/com.xyzapp.app/cache/temp_file.docx //this is getpathhh
below is my code
first activity:-
val browseintent = Intent(this, WebviewActivityNew::class.java)
browseintent.putExtra("url", "file://"+getpathhh.toString())
startActivity(browseintent)
second Activity:-
val url = intent.extras!!.getString("url")
webview_comp.getSettings().setLoadsImagesAutomatically(true);
webview_comp.getSettings().setJavaScriptEnabled(true);
webview_comp.getSettings().setAllowContentAccess(true);
webview_comp.getSettings().setAllowFileAccess(true);
webview_comp.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webview_comp.getSettings().setAppCachePath(url);
webview_comp.getSettings().setAppCacheEnabled(true);
webview_comp.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
url?.let { webview_comp.loadUrl(it) };
if i use Action_view
val pdfOpenintent = Intent(Intent.ACTION_VIEW)
pdfOpenintent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
pdfOpenintent.setDataAndType(Uri.fromFile(getpathhh), "*/*")
try {
startActivity(pdfOpenintent)
} catch (e: ActivityNotFoundException) {
}
im getting crash as 'E/UncaughtException: android.os.FileUriExposedException: file:///data/user/0/com.xyzapp.app/cache/temp_file.docx exposed beyond app through Intent.getData()'
following what i have tried
val pdfOpenintent = Intent(Intent.ACTION_VIEW)
pdfOpenintent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
pdfOpenintent.setDataAndType(
FileProvider.getUriForFile(
applicationContext,
"com.xyzapp.app.provider",
getpathhh
), "*/*")
try {
startActivity(pdfOpenintent)
} catch (e: ActivityNotFoundException) {
}