Lompat ke konten Lompat ke sidebar Lompat ke footer

Widget HTML #1

WebView Manager Programmatically Full Fungsi Dengan Penjelasan - Android Studio

program android studio ketika ingin menggunkana webview dengan fungsi download, convert html menjadi java, management webview yang wajib.


Layoutnya : 

<WebView
android:layout_width="match_parent"
android:layout_marginLeft="65dp"
android:id="@+id/Utama"
android:layout_height="match_parent"></WebView>


Javanya : 


final WebView webView = (WebView) findViewById(R.id.Utama);

webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);

// Tiga baris di bawah ini agar laman yang dimuat dapat
// melakukan zoom.
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(false);
webView.getSettings().setUserAgentString(null);

// Baris di bawah untuk menambahkan scrollbar di dalam WebView-nya
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

//------------------------------//
//next aktifity
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {

//deteksi dalam html apakah ada (string) maka akan berubah fungsi ke sini dan di deklarasi
if (url.startsWith("tel:") || url.startsWith("sms:") || url.startsWith("smsto:") || url.startsWith("mailto:") || url.startsWith("mms:") || url.startsWith("mmsto:")) {
//membuka action view ketika html onclick di pilih
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
else {
view.loadUrl(url);
}
return false;
}
});
webView.loadUrl("https://www.faranramdan.com/p/list-config-pubg-mobile-update-tiap.html");
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setMimeType(mimetype);
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
request.addRequestHeader("User-Agent", userAgent);
request.setDescription("Downloading File...");
request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimetype));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(
url, contentDisposition, mimetype));
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
Toast.makeText(getApplicationContext(), "Downloading File", Toast.LENGTH_LONG).show();
}
});

Posting Komentar untuk "WebView Manager Programmatically Full Fungsi Dengan Penjelasan - Android Studio"