从我的WebView中的相机或图库上传图像

时间:2017-11-15 02:18:14

标签: java android android-webview

我已经在app上将我的网站转换为使用webview的app 我想从相机或图库上传图像 我想添加例如,如果我想在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();
    }

AndroidManifest

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

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

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

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

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

1 个答案:

答案 0 :(得分:0)

尝试使用“WebClientListener”并覆盖“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(prelolipop)。