Open web page with app in Android Studio

0

I have a question about an app that I was asked for, in my work they have a website that contains videos for automatic playback, what I should do with my app is to enter that page in full screen mode. That I already do and test and it works without problems, but when I install the apk on a cell phone to do the tests, I open the desired page and I open the cell phone browser too, and when that happens the page in my app redirects me to the root of the page (the page is link and it returns me to link ). This is the code of my app:

package com.example.serverssupport.myapplication;


import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                         WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);

    WebView web = new WebView(this);
    setContentView(web);
    web.loadUrl("http://172.16.10.3/slider");

}

}

Is there something wrong in the code for that to happen? How could I avoid it? Thank you in advance for your support I say goodbye.

    
asked by lfsalazar2010 21.06.2018 в 19:33
source

1 answer

1

Maybe you just need to add this:

...

 String url = "http://172.16.10.3/slider";

...

    web.getSettings().setJavaScriptEnabled(true);
    web.setWebViewClient(new WebViewClient(){
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url){
          view.loadUrl(url);
          return true;
        }
    });

This way you can navigate through your web page without being redirected to the default browser of the phone and always kept within your application.

    
answered by 21.06.2018 в 21:27