首页 > 解决方案 > 如何修复 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 设备拍照的能力

标签: android

解决方案


尝试将此代码添加到您的onCreate()

webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

推荐阅读