I'm currently working on simple android app webview. My website is opencart version 2.3.0.2 with default template. Web is working fine using browser for all devices tested desktop, mobile, tab. And on android also work fine except for checkout page (6 step). Its like not clickable and the tab not opening its content. I guess its because ajax/jquery on that page having conflict with android. Anyone having this experience? Mind to share where/what to fix to get it work?
This what i've in MainActivity.java:
public class MainActivity extends AppCompatActivity {
private WebView mWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//setSupportActionBar(toolbar);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://www.example.com");
mWebView.setWebViewClient(new WebViewClient());
}
}
Solved by adding
setDomStorageEnabled(true)
in MainActivity.java.
Related
All. I am working on web view based android application, and need to access one URL which has got windows authentication (Negotiate, NTLM) protected.
I did some code and make it work on the emulator.
But unfortunately, It doesn't work on devices.
I tested with Samsung s8 (Android 9.0), Samsung Tab A (Android 8.1)
Below is the code that I tried to integrate a web view on my application.
As I mentioned, it correctly works on the emulator but not on a device
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = findViewById(R.id.activity_main_webview);
// Enable Javascript
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setDefaultTextEncodingName("utf-8");
// REMOTE RESOURCE
mWebView.loadUrl("https://palmerston.wheelers.co/account/logon");
mWebView.setWebViewClient(new MyWebViewClient());
}
--> MyWebViewClient
#Override
public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
String username="123";
String userpass="123";
handler.proceed(username, userpass);
}
I wonder if there is any other configuration or what causes authentication stopping on device webview.
Please help me to solve this problem, if you have faced this kind of issue before.
Thank you.
I have frontend and backend ready and working on localhost. I am displaying the frontend website threw the android emulator:
public class MainActivity extends AppCompatActivity {
private WebView webview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview =(WebView)findViewById(R.id.webView);
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
webview.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
webview.loadUrl("http://10.0.2.2:4200/mobile");
}
}
The problem is that emulator can't get the data from database or send request to api to recieve the data so that it's not displayed. How it looks on a website:
Once again the problem is straight with emulator. I tried building the frontend in production mode with no success. This issue looks strange to me because I am just "retranslating" the working website. Maybe I should declare a special permission or sth like that.
Android Studio Error:
I just started the Android Studio two days ago and I've never experienced Java before. However, I know the language to build a website. I've finished creating a hybrid app to render my website as an app in a WebView. I want to change the design and the title of AlertDialog from my WebView, how could I do it?
MainActivity.java
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView WebView01 = (WebView) findViewById(R.id.webView);
WebView01.setWebChromeClient(new WebChromeClient());
WebView01.setWebViewClient(new WebViewClient());
WebSettings webSettings = WebView01.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setBuiltInZoomControls(false);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setSupportMultipleWindows(true);
webSettings.setSaveFormData(false);
webSettings.setSavePassword(true);
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
WebView01.loadUrl("http://url");
}
}
There are many tutorials available online. You can create custom AlertDialog and you can give whatever design you want and load WebView on that AlertDialog
create a custom dialog box
Android custom dialog example
How to create a Custom Dialog box in android?
I developed an Android Web App completely in a WebView.
This app opens my website and is working very perfectly.
But the only problem is: My website is integrated with Tawk.to Widget, which enables visitors to chat live with our customer care.
This widget plays sound when someone joins the conversation & replies something.
But this Android app is not playing any sound.
But the same is working well when I open my website in Mobile Browser.
Can anyone help me enable sounds for a Web App like this?
private WebView mywebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mywebView = (WebView)findViewById(R.id.webView);
WebSettings webSettings = mywebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mywebView.loadUrl("http://getmore.tech/user/Default.aspx");
mywebView.setWebViewClient(new WebViewClient());
}
#Override
public void onBackPressed() {
if(mywebView.canGoBack()){
mywebView.goBack();
} else {
super.onBackPressed();
}
}
You might need to enable media playback without requiring a user gesture: webSettings.setMediaPlaybackRequiresUserGesture(false);.
I'm working on an Android app where, basically, different web pages are embedded in fragments and a list fragment is used to switch between pages. I'm able to get HTML5 location data working through a browser but not when the page is embedded in the app.
Forgetting fragments, I was able to and I can get JavaScript working in the WebView. But even with WebViewClient I can't figure out what to do for getting the geolocation data working. Can someone point me in the right direction?
You have first to Enable Javascript and GeoLocation in your WebView
WebView mWebView;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webView1);
// Brower niceties -- pinch / zoom, follow links in place
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.setWebViewClient(new GeoWebViewClient());
// Below required for geolocation
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setGeolocationEnabled(true);
mWebView.setWebChromeClient(new GeoWebChromeClient());
}
then you can get location data using navigator..
function getLocation() {
navigator.geolocation.getCurrentPosition(displayLocation, handleError);
}
Take a look at this Post