1

I'm looking for help with this code. I need to add that you can upload files from this application. But I can not make it work as well .... So this works great. What I could do is download, but not upload files. As I can do? I leave the code below. please be explicit and specific.Consider that only supports Android 3.0>.

I mean this is a WebView which one when you are on the website Facebook touches the button to upload an image and a box that lets you choose if you take a picture or look in the device is opened. I want that. As I can do?

public class MainActivity extends ActionBarActivity {

    private WebView mWebView;
    private ProgressBar progressBar;

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

        // Enable Javascript
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        mWebView.loadUrl("file:///android_asset/www/index.html");
        // Force links and redirects to open in the WebView instead of in a browser
        mWebView.setWebViewClient(new WebViewClient());
        // enable local storage
        // enable local storage
        mWebView.setDownloadListener(new DownloadListener() {
            public void onDownloadStart(String url, String userAgent,
                                        String contentDisposition, String mimetype,
                                        long contentLength) {
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(url));
                startActivity(i);
            }
        });

        webSettings.setBuiltInZoomControls(true);
        webSettings.setSupportZoom(true);


        progressBar = (ProgressBar) findViewById(R.id.progressbar);

        mWebView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int progress) {
                progressBar.setProgress(0);
                progressBar.setVisibility(View.VISIBLE);
                MainActivity.this.setProgress(progress * 1000);

                progressBar.incrementProgressBy(progress);

                if (progress == 100) {
                    progressBar.setVisibility(View.GONE);
                }
            }
        });

    }


    @Override
    public void onBackPressed() {
        if (mWebView.canGoBack()) {
            mWebView.goBack();
        } else {
            // Let the system handle the back button
            super.onBackPressed();

        }
    }


    public class MyAppWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (Uri.parse(url).getHost().length() == 0) {
                return false;
            }

            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            view.getContext().startActivity(intent);
            return true;
        }

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
Ashot Karakhanyan
  • 2,804
  • 3
  • 23
  • 28
GusGeek
  • 11
  • 1
  • 5

1 Answers1

0

The answer to your question is here.

You will need to implement

1. "openFileChooser" for android>3 and for android >4.1
2. "showAttachmentDialog"
3. "onActivityResult"

This way a file chooser window will pop up and you will be able to upload your file

this is how I used the same method in my code in a similar way.

Hope that helps

Community
  • 1
  • 1
magmike
  • 473
  • 1
  • 5
  • 18