我正在WebView
中渲染网站,我的问题是,当我尝试上传个人资料图片或任何图片(不存在相机选项时,我无法访问相机),而在浏览器中打开时,一切正常完全符合预期)。
我是android的新手,因此在使用WebView
时我无法弄清楚该怎么做,在本教程中,有一种非常简单的方法。
我尝试了很多事情,但是没有任何效果。 需要帮助!
这是我的MainActivity
代码:
public class MainActivity extends Activity implements
AdvancedWebView.Listener, View.OnClickListener {
private AdvancedWebView mWebView;
private WebSettings webSettings;
private DhanVapasiWebChromeClient dhanVapasiWebChromeClient;
private RelativeLayout childLayout;
private RelativeLayout browserLayout;
private Button mainCloseButton;
private TextView titleText;
private Context mContext;
private Activity mActivity;
protected final Map<String, String> mHttpHeaders = new
HashMap<String, String>();
private static final int FILECHOOSER_RESULTCODE = 2888;
private ValueCallback<Uri> mUploadMessage;
private Uri mCapturedImageURI = null;
private PermissionRequest mPermissionRequest;
private static final int REQUEST_CAMERA_PERMISSION = 1;
private static final String[] PERM_CAMERA =
{Manifest.permission.CAMERA};
// declarations ends here !
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContext = getApplicationContext();
mActivity = MainActivity.this;
setUpWidgets();
if(isChildOpen()){
dhanVapasiWebChromeClient.closeChild();
mWebView.reload();
}
mWebView = (AdvancedWebView) findViewById(R.id.webview);
mWebView.setListener(this, this);
mWebView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String
url){
//Override those URLs you need and return true.
//Return false if you don't need to override that URL.
Log.d("should_override", "THIS IS URL:"+url);
if (url.endsWith(".mp4")) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "video/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
view.getContext().startActivity(intent);
// If we return true, onPageStarted, onPageFinished
won't be called.
return true;
} else if (url.startsWith("whatsapp:")) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(url));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
view.getContext().startActivity(intent);
return true; // If we return true, onPageStarted,
onPageFinished won't be called.
}
else if(url.startsWith("mailto:")){
handleMailToLink(url, mWebView);
}
else{
view.loadUrl(url,mHttpHeaders);
}
return true;
}
});
webSettings = setupWebView(mWebView.getSettings(), this);
mWebView.addHttpHeader("X-device","AndroidApp");
mHttpHeaders.put("X-device", "AndroidApp");
dhanVapasiWebChromeClient = new
DhanVapasiWebChromeClient(MainActivity.this, childLayout,
browserLayout, titleText, mWebView);
mWebView.setWebChromeClient(dhanVapasiWebChromeClient);
mWebView.loadUrl(WEBAPP_URL);
}
// handles initial setup of webview first time initialization ,
javascript enable bla bla
public WebSettings setupWebView(WebSettings webSettings,
Activity activity) {
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setGeolocationEnabled(false); // normally set true
webSettings.setDomStorageEnabled(true);
webSettings.setPluginState(WebSettings.PluginState.ON);
webSettings.setSupportMultipleWindows(true);
// accept cookies keep it in with cookiemanager
CookieManager.getInstance().setAcceptCookie(true);
webSettings.setGeolocationEnabled(true);
return webSettings;
}