如果 webview html 内容几乎没有<img>标签,当用户在 webview 中点击图像时,是否可以在新活动中以全屏模式打开该图像?
当我在 Web 视图上加载youtube.com时,它显示“请在浏览器上启用 Java 脚本”。
我已经getJavaScriptEnabled(true)在我的代码中完成了。回答?
javascript android android-layout android-webview cordovawebview
我想将以下视频嵌入到 Android Web 视图中: https://www.espn.com.ar/core/video/iframe ?id=6034792&endcard=false&omniReportSuite=wdgespg
我尝试了不同的网络视图方法,但没有任何结果。没有错误,我只能查看播放器,但无法播放。
//显现:
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:hardwareAccelerated="true">
Run Code Online (Sandbox Code Playgroud)
//代码:
String html = String.format("<iframe src=\"%s\" width=\"340\" height=\"313\" style=\"border:none;overflow:hidden\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\"></iframe>", url.getSrc());
wview.loadDataWithBaseURL("https://www.espn.com.ar", html, "text/html", "UTF-8", null);
//OR
wview.loadUrl(url.getSrc());
//MY WEBVIEW:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:wheel="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true">
<WebView
android:id="@+id/wview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 这个问题与我认为的所有 Android Chrome 浏览器相关,但就我而言,我使用的是 React-native WebView(它正在编译为应用程序中的本机 webview)。我应该补充一点,这在 iOS 上工作得很好,因为指向 PDF 的 URL 只会在浏览器中加载该 PDF。
所以,我想知道是否有办法强制 Chrome 浏览器使用标头在浏览器中加载 PDF?
或者,是否有一个 URL 允许您将 PDF url 作为参数传递?某种代理服务。
有任何想法吗?
WebAppInterface使用Jetpack Compose时如何实现(webview的javascript接口)?
我正在关注这个文档
这是我到目前为止已经走了多远,但showToast()没有被调用。添加@Composable到showToast()没有帮助。
/** Instantiate the interface and set the context */
class WebAppInterface(private val mContext: Context) {
/** Show a toast from the web page */
@JavascriptInterface
fun showToast(toast: String) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show()
}
}
@SuppressLint("SetJavaScriptEnabled")
@Composable
fun WebPageScreen(urlToRender: String) {
AndroidView(factory = {
WebView(it).apply {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
webViewClient = WebViewClient()
addJavascriptInterface(WebAppInterface(getContext()), "Android")
loadUrl(urlToRender)
}
}, update = {
it.loadUrl(urlToRender)
})
}
Run Code Online (Sandbox Code Playgroud)
Android 文档中的 HTML/JS …
android-webview kotlin android-jetpack android-jetpack-compose
我们连接到 https。如果 Android 设备上有 Chrome 浏览器,我们就可以在启用相机和麦克风的情况下进行连接。也能够打开和关闭它们。但是,如果我们使用网络视图尝试相同的操作,我们甚至不会收到网站授权访问的提示,并在尝试打开它们时出现“无法访问摄像头/麦克风”错误。
显现
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.webkit.PermissionRequest" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Run Code Online (Sandbox Code Playgroud)
网页视图活动
class WebView : AppCompatActivity() {
val permission = arrayOf(Manifest.permission.CAMERA,
Manifest.permission.RECORD_AUDIO,
Manifest.permission.MODIFY_AUDIO_SETTINGS)
val requestCode = 1
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_web_view)
WebViewSetup()
if (!isPermissionGranted()) {
askPermissions()
}
}
private fun askPermissions() {
ActivityCompat.requestPermissions(this, permission, requestCode)
}
private fun isPermissionGranted(): Boolean {
permission.forEach {
if (ActivityCompat.checkSelfPermission(this, it) != …Run Code Online (Sandbox Code Playgroud) 我有一个相当简单的网络表单。访问网络表单的唯一人是使用移动设备,因此我使用移动设备构建了表单。
为了让用户更简单,我有两个文件上传按钮(这里的 HTML 并不是太重要,除了解释我正在尝试做什么以及为什么我无法解决它)。一个上传按钮是一个简单的上传按钮,用户可以在其中导航他们的文件。第二个上传按钮应该立即打开相机。
当我在移动浏览器上打开表单时,这工作正常。
<div class = "col-6-6">
<label class = "image-label label-upload">
<span class = "icons i-upload"></span>
Upload
<input name="image-upload" type = "file" accept="image/*">
</label>
</div>
<div class = "col-6-6">
<label class = "image-label label-upload">
<span class = "icons i-camera"></span>
Capture
<input name="image-capture" type = "file" accept="image/*" capture = "environment">
</label>
</div>
Run Code Online (Sandbox Code Playgroud)
我现在尝试做的是使用 webview 模拟浏览器与应用程序完全相同的行为。
package com.example.testapp
import android.os.Bundle
import android.webkit.WebChromeClient
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
supportActionBar?.hide() …Run Code Online (Sandbox Code Playgroud) 我正在开发一个Android 3.0平板电脑的应用程序,它应该在WebView中播放swf文件.首先,我尝试从设备打开swf文件,而不是通过互联网,没有运气.WebView显示,但在WebView中我只能看到一个黑屏(右侧有3-4 px宽的白线).如果我将相同的URL加载到设备浏览器,则Flash文件可以正常播放.我想我在WebView设置上遗漏了一些东西,但经过几个小时的搜索和谷歌搜索后,我仍然不知道是什么.
Java代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.presentation);
presentationWebView = (WebView) findViewById(R.id.presentation_webview);
presentationWebView.getSettings().setJavaScriptEnabled(true);
presentationWebView.getSettings().setPluginsEnabled(true);
presentationWebView.getSettings().setAllowFileAccess(true);
presentationWebView.loadUrl("http://my_domain/fileName.swf");
Run Code Online (Sandbox Code Playgroud)
}
presentation.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:id = "@+id/presentation_webview"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
谢谢你非常怀疑任何答案.Ripityom
我正在尝试将Web视图加载到对话框中.我正在使用以下代码.
final TextView seeMonthlyBill = (TextView) parentLayout
.findViewById(R.id.my_ac_my_service_timewarnercable_link);
seeMonthlyBill.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Dialog dialog = new Dialog(getActivity());
WebView wb = new WebView(getActivity());
wb.getSettings().setJavaScriptEnabled(true);
wb.loadUrl("http://www.google.com");
wb.setWebViewClient(new HelloWebViewClient());
dialog.setCancelable(true);
dialog.setContentView(wb);
dialog.setTitle("WebView");
dialog.show();
}
});
Run Code Online (Sandbox Code Playgroud)
我想在单击文本视图时打开Web视图.当我点击文本视图对话框时,没有webview打开.有什么可以帮我解决这个问题.
提前致谢.
如果我单击webview中的链接,则永远不会调用shouldOverrideUrlLoading().(它不显示吐司或记录任何东西).我也尝试了onPageFinished,它也没有被调用.我读过其他帖子,其中用户遇到的问题有时候不会被调用,但在我的情况下,它完全被忽略了.
webview = new WebView(MyActivity.this);
webview.getSettings().setBuiltInZoomControls(true);
webview.getSettings().setDisplayZoomControls(false);
webview.loadData(Html.getHtml(), "text/html", "UTF-8");
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
new M("shouldOverrideUrlLoading",getApplicationContext());
Log.v("ESSE3", "shouldOverrideUrlLoading()");
System.out.println(url);
System.out.println(Html.getHtml());
webview.loadData(Html.getHtml(), "text/html", "UTF-8");
return true;
}
});
webview.setWebViewClient(new WebViewClient());
setContentView(webview);
Run Code Online (Sandbox Code Playgroud)
尝试启用/不启用javascript或在方法中返回true或false.
android-webview ×10
android ×9
webview ×4
kotlin ×3
embed ×1
flash ×1
javascript ×1
react-native ×1
video ×1