1

I am in my first application in WebView. I have a page in my app that allows the user to upload a picture from the gallery of photos of the device to change the avatar.

However, when I test the app, the button doesn't do anything. I tap, tap, tap, double tap ! nothing happens...

I have seen a lot of posts, I tried a lot too, nothing seems to work, some say it is not possible in webview, others say it is not anymore the same method since Lollipop etc... In other words : I AM LOST !

Here is the code of my MainActivity.java :

package com.example.app;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;



public class MainActivity extends Activity {

    private WebView mWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mWebView = (WebView) findViewById(R.id.activity_main_webview);

        // Force links and redirects to open in the WebView instead of in a browser
        mWebView.setWebViewClient(new WebViewClient());

        // Enable Javascript
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        // Use remote resource
        mWebView.loadUrl("http://urlofmywebsite");

        // Stop local links and redirects from opening in browser instead of WebView
        //mWebView.setWebViewClient(new MyAppWebViewClient());

        // Use local resource
        // mWebView.loadUrl("file:///android_asset/www/index.html");

    }

    // Prevent the back-button from closing the app
    @Override
    public void onBackPressed() {
        if(mWebView.canGoBack()) {
            mWebView.goBack();
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.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();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
FrenchyNYC
  • 337
  • 1
  • 6
  • 23

2 Answers2

0

you need to change you local file to bytearray and convert it into Base64 string and needs to hit your server URL with that content using some keyword to identify this content and then needs to change it into your it in server to get that content. If you want code help pls inform. Another option is to use some services yo send that content to server URL link and send it to your server URL that http URL simply.

  • Hello and thank you for your fast answer. However, I am a total NOOB and all I understood is that I was in deep sh*t. So yes if you could give me what to put and where, that would be GLADLY appreciated ! – FrenchyNYC Dec 13 '15 at 14:44
0

do you want to get link first from your server about the image you want to send, and then simply load URL to webview or you want image to go locally.

  • Well, my website is a Wordpress. So I don't know what to do. There is just a page where the user can upload a picture for his profile picture (Buddypress plugin). So normally, they click on the button "send picture" and it opens the gallery, they choose their picture and basta... Like the browser does, it works fine. It is just that on the webview, it is disable... So tell me the best ! Here is the code of the webview I am using : https://github.com/slymax/webview – FrenchyNYC Dec 13 '15 at 18:04