Android emulator can't get api data threw website - android

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:

Related

Android : webview : getting error code -6 net::ERR_CONNECTION_REFUSED

I keep getting errorcode -6 and description net::ERR_CONNECTION_REFUSED on android webview in
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final WebView webview =(WebView) this.findViewById(R.id.webView);
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webview.setWebViewClient(new MyWebViewClient());//I only implemented onReceivedError to display the errors in logcat
webview.loadUrl("http://mydomainexample.com");// it loads http://google.com but throws error code = -6 for my doamin which works fine in any navigator
}
while the exact same url (example http://aaaaaaaaa.com) works well in any navigator, do webviews make connections differently from navigators?
What could be causing this issue?
Maybe due to cookie request by the website (see Android Webview error code -6) but please post your code. There is also a posting on https://github.com/ionic-team/capacitor/issues/1848
The issue was that the loaded webpage had a js file that, asynchronously, made a request to a port which was blocked on the server. I've tried removing that request and it worked

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>

How to enable sounds for Web View in Android App Development?

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);.

phonegap function not working in webview

I am trying to build a simple app using webview but unable to get phonegap functions working when I use the webview class. If I use "super" then the phonegap function works fine. Excuse my odd vocabulary.
///////////////// JAVA //////////////////////////
public class MainStart extends DroidGap {
HTML5WebView mWebView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CookieSyncManager.createInstance(this);
CookieSyncManager.getInstance().sync();
mWebView = new HTML5WebView(this);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.addJavascriptInterface(new JavaScriptInterface(this), "MyAndroid");
mWebView.getSettings().setPluginsEnabled(true);
mWebView.loadUrl("file:///android_asset/www/index.html"); // phonegap function does not work
super.loadUrl("file:///android_asset/www/index.html"); // phonegap function works here
}
}
///////////////// JAVASCRIPT //////////////////////////
function onDeviceReady(){
navigator.notification.alert("PhoneGap is working");
}
the WebView that PhoneGap sets up include a multitude of features which you are not even referencing in your own WebView - like the Javascript bridge - without it there's no way you can call Native code from within your html page!
may I ask why exactly are you trying to re-create your own WebView, instead of just using the standard supplied one?

how to run local web application in android webview

can anybody tell how to run the local webapplication using android webview
I want to run my own webpages in android using web view
Thanks
I'm guessing you want something like this:
private WebView mWebView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yourLayoutWithAWebView);
mWebView = (WebView)findViewById(R.id.yourWebViewIdFromTheLayout);
mWebView.getSettings().setJavaScriptEnabled(true); // Enable JavaScript
mWebView.loadData(yourHtmlData, "text/html", "utf-8");
}
Hopefully, that at least points you in the right direction.
Also, I'd recommend reading the documentation on the WebView, it's pretty thorough.
Just run your application on the emulator, as you normally do (and be sure to have your computer connected to internet).

Categories

Resources