有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java从my WebView中的摄像头或图库上传图像

我已经在应用程序上使用webview将我的网站转换为应用程序 我想从相机或画廊上传图片 例如,如果我想在facebook上分享,它需要打开facebook应用程序,或者如果我点击链接,它需要让我出去 我应该更改或添加什么? 谢谢!

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    webview = (WebView) findViewById(R.id.webview);
    webView();
}

//Metodo llamar el webview
private void webView() {
    //Habilitar JavaScript (Videos youtube)
    webview.getSettings().setJavaScriptEnabled(true);

    //Handling Page Navigation
    webview.setWebViewClient(new WebViewClient());

    //Load a URL on WebView
    webview.loadUrl("http://www.nehmen-geben.com/");
}

// Metodo Navigating web page history
@Override
public void onBackPressed() {
    if (webview.canGoBack()) {
        webview.goBack();
    } else {
        super.onBackPressed();
    }

雄激素单

<?xml version="1.0" encoding="utf-8"?>

<uses-permission 安卓:name="安卓.permission.INTERNET" />

<application
    安卓:allowBackup="true"
    安卓:icon="@mipmap/ic_launcher"
    安卓:label="@string/app_name"
    安卓:supportsRtl="true"
    安卓:theme="@style/AppTheme">
    <activity 安卓:name=".MainActivity">

    </activity>
    <activity 安卓:name=".splash">
        <intent-filter>
            <action 安卓:name="安卓.intent.action.MAIN" />

            <category 安卓:name="安卓.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>


共 (1) 个答案

  1. # 1 楼答案

    尝试使用“WebClient Listener”并覆盖“shouldOverrideUrlLoading”

    webView.setWebViewClient(new WebClientListener());
    

    private class WebClientListener extends WebViewClient { //other callback...... @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { //Intercept the url you specified in this method. //e.g. Define a specified url like "http://yourhost.com/shareToFacebook" //in your html and when you cathch this url, use the facebook's sdk to share, //and return "true" to tell the webview to handle such url yourself. // //If you want to open the browser outside,you can use: //Uri uri = Uri.parse(url); //Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    //startActivity(intent);
    } }

    如果你只想在webview中上传类似照片的文件,你可以试试

    webView.setWebChromeClient(new WebChromeClient());
    

    重写接口的onShowFileChooser(在棒棒糖之后)和openFileChooser(前olipop)