How to enable sounds for Web View in Android App Development? - 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);.

Related

Why the windows authentication works on emulator webview but not on device?

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.

Payment processing infinitely in WebView

I have a testing website where PayUMoney payment processing in test mode is working perfect.
I used the same url in webview and also enabled javascript, but the payment is processing infinitely(Loading forever).
Please help me figure out this. Thanks!
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("https://gatewaypayment.000webhostapp.com");
}
#Override
// This method is used to detect back button
public void onBackPressed() {
if(webview.canGoBack()) {
webview.goBack();
} else {
// Let the system handle the back button
super.onBackPressed();
}
}
}
I faced a similar situation but finally figured out that the reason behind the long loading is due to the test details getting updated frequently, or the test environment that PayUMoney provides itself is down. Also make sure of the following:
To test the Bolt Checkout in the test mode, you need to change the JavaScript libraries used as-well as use Test Mode key and salt for hash generation.
So while integrating in Test Mode, include the script as shown below in the head section of your payment request page.
<script id="bolt" src="https://sboxcheckout-static.citruspay.com/bolt/run/bolt.min.js" bolt-
color="<color-code>"
bolt-logo="<image path>">
</script>
Once your integration is done and tested on the sandbox, replace the sandbox JavaScript library with the production library provided by PayU.
<script id="bolt" src="https://checkout-static.citruspay.com/bolt/run/bolt.min.js" bolt-color="<color-
code>"
bolt-logo="<image path>">
</script>

Android emulator can't get api data threw website

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:

Android app webview ajax not working on checkout page opencart

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.

How do you get location data through HTML5 embedded in an Android app?

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

Categories

Resources