android - 如何修复 WebView“阻止弹出窗口”?
问题描述
我正在尝试使用 WebView 打开我们的项目应用程序,当我们用 android 设备录制照片时,不会出现弹出窗口。但是,当我使用浏览器访问应用程序时,会出现弹出窗口,我们可以选择相机。我需要在哪里更新代码?
//主要活动 //
public class MainActivity extends Activity {
public WebView webView ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
webView = (WebView)findViewById(R.id.WebView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("https://projectapp.com");
webView.setWebViewClient(new WebViewClient());
}
// 显现 //
package="com.rolloutapp.projectapp.simpleapp">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.rolloutapp.projectapp.simpleapp.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
使用带有 WebView 的 android 设备拍照的能力
解决方案
尝试将此代码添加到您的onCreate()
:
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
推荐阅读
- python - 在搜索栏中输入查询并抓取结果
- django - 在基于类的视图中设置基于条件的重定向 (Django)
- java - spring boot java中线程“main”java.awt.HeadlessException中的异常
- python - 无法修复 ValueError("endog 必须在单位区间内")
- javascript - 我可以在 JSON 数据 Javascript 中更改索引 ID 或排序数据吗
- android - Android Fragment 导航返回上一页
- python - 为什么等效着色器输出不同的结果?
- unity3d - 为什么当两个对象彼此靠近时,Vector3.Distance 返回的值会变大
- r - 提取相关投资组合的权重
- entity-framework - .NET Core Web API 在数据库上下文中更新模型不起作用