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);
}
}
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.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments