Hello! Sorry, I am a super beginner, answer please write carefully, preferably fool tutorial, I contact this is only a month, less than half an hour a day on average. Here is my version AS: < br / >
< div class = "aw - list - img >
As shown in the figure below, on the basis of the existing code, the Webview can make the button in the red area realize horizontal and full screen playback when loading the video and audio on the web page, and realize the download of the video and audio:
Here is my MainActivity.java
package com.example.hao;
import android.os.Build;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private WebView webview;
private String APP_CACAHE_DIRNAME;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview = (WebView) findViewById(R.id.webview);
webview.setWebViewClient(new WebViewClient());
webview.setWebChromeClient(new WebChromeClient());
webview.requestFocus();
webview.loadUrl("http://www.dengzhoushixichengnianfotangjingtuwenhuachuanmei.com/");
// 设置web视图客户端
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setPluginState(WebSettings.PluginState.ON);
webSettings.setSupportZoom(true); //支持缩放,默认为true。是下面那个的前提。
webSettings.setBuiltInZoomControls(true); //设置内置的缩放控件。若为false,则该WebView不可缩放
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
webSettings.setDisplayZoomControls(false); //隐藏原生的缩放控件
}
//其他细节操作
webSettings.setAllowFileAccess(true); //设置可以访问文件
webSettings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口
webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片
webSettings.setDefaultTextEncodingName("utf-8");//设置编码格式
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
webSettings.setTextZoom(100);
}
//结合使用(离线加载)
webSettings.setDomStorageEnabled(true);//启用Dom存储
webSettings.setDomStorageEnabled(true); // 开启 DOM storage API 功能
webSettings.setDatabaseEnabled(true); //开启 database storage API 功能
webSettings.setAppCacheEnabled(true);//开启 Application Caches 功能
String cacheDirPath = getFilesDir().getAbsolutePath() + APP_CACAHE_DIRNAME;
webSettings.setAppCachePath(cacheDirPath); //设置 Application Caches 缓存目录
//优先使用缓存:
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
//缓存模式如下:
//LOAD_CACHE_ONLY: 不使用网络,只读取本地缓存数据
//LOAD_DEFAULT: (默认)根据cache-control决定是否从网络上取数据。
//LOAD_NO_CACHE: 不使用缓存,只从网络获取数据.
//LOAD_CACHE_ELSE_NETWORK,只要本地有,无论是否过期,或者no-cache,都使用缓存中的数据。
//不使用缓存:
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
}
@Override
public void onBackPressed() {
if (webview.canGoBack()){
webview.goBack();
}else {
super.onBackPressed();
}
}
}
The corresponding layout file for
is:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"></WebView>
</androidx.constraintlayout.widget.ConstraintLayout>
This is the androidmanifest xmln
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.hao">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/logo"
android:label="@string/邓州市西城念佛堂净土文化传媒"
android:roundIcon="@mipmap/roundlogo"
android:supportsRtl="true"
android:theme="@style/Theme.Hao"
android:usesCleartextTraffic="true"
android:hardwareAccelerated="true"
android:configChanges="keyboardHidden|orientation|screenSize"
tools:targetApi="31">
<activity
android:name=".Welcome"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
</activity>
</application>
</manifest>
Also, when the webview loads a page on a web page where you can download audio, it looks like this:
< div class = "aw - list - img >
Please point, as long as I copy into the file, can achieve full screen video playback, can download video and audio files, will be adopted, thank you!
0 Answer
No answer yet
这家伙很懒,什么都没留下...