我有以下链接
它包含一个html5视频,我尝试将其加载到我的android应用中的webview内
它会一直加载并且永远不会运行,我尝试启用javascript并添加了很多配置,但是也无法正常工作
我什至尝试使用AdvancedWebView sdk进行渲染,在这种情况下,它会加载但没有运行任何东西
任何人都可以帮忙吗?
答案 0 :(得分:0)
您可以使用以下代码加载页面:
MainActivity.java
public class MainActivity extends AppCompatActivity {
protected AgentWeb mAgentWeb;
private LinearLayout mLinearLayout;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_main);
mLinearLayout = findViewById(R.id.web_content);
mAgentWeb = AgentWeb.with(this)
.setAgentWebParent(mLinearLayout, new LinearLayout.LayoutParams(-1, -1))
.closeIndicator()
.setWebChromeClient(mWebChromeClient)
.setWebViewClient(mWebViewClient)
.setMainFrameErrorView(R.layout.agentweb_error_page, -1)
.setAgentWebWebSettings(getAgentWebSettings())
.setSecurityType(AgentWeb.SecurityType.STRICT_CHECK)
.setOpenOtherPageWays(DefaultWebClient.OpenOtherPageWays.ASK)
//.interceptUnkownUrl()
.createAgentWeb()
.ready()
.go("http://stage.diabetesmasterclass.org/Upload/myclinic/SAM/visit1/sam_storyline_output/story_html5.html");
}
private WebChromeClient mWebChromeClient = new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
}
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
}
};
private WebViewClient mWebViewClient = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
return super.shouldOverrideUrlLoading(view, request);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
Log.i("Info", "BaseWebActivity onPageStarted");
}
};
public @Nullable
IAgentWebSettings getAgentWebSettings() {
return AgentWebSettingsImpl.getInstance();
}
@Override
protected void onPause() {
mAgentWeb.getWebLifeCycle().onPause();
super.onPause();
}
@Override
protected void onResume() {
mAgentWeb.getWebLifeCycle().onResume();
super.onResume();
}
@Override
protected void onDestroy() {
super.onDestroy();
mAgentWeb.getWebLifeCycle().onDestroy();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == 2) {
mAgentWeb.getIEventHandler().back();
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Top"
android:textSize="22dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/web_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Bottom"
android:textSize="22dp" />
</LinearLayout>
</LinearLayout>
使用此Webview
更新输出看起来像this