Top

WebView Android loading Angular 7 app didn't load #minivideo at first time

Comments

4 comments

  • Konrad Hyzy

    Hello,

     

    The problem may be coming from the fact that mobile browsers prevent the websites to run the content automatically (as in the case of videos).

    Does this problem occur when you try to run both applications on a desktop browser? 

    At the moment it is suggested to use Rainbow SDK for Android while developing the mobile apps for this system. 

     

    Best regards,

    Konrad Hyzy

     

    0
    Comment actions Permalink
  • Jesús Giménez

    Thanks for your answer Konrad. Finally i got the solution.

    I post here for others in my situation, simply added new websetting to WebView:

    webSettings.setMediaPlaybackRequiresUserGesture(false);

    Now the video shows correctly when answering calls.

     

    Thanks!!

    1
    Comment actions Permalink
  • Vamsi Konanki

    Hi Jesús Giménez,

     

    It's Good to know that Instead of Native SDK for Android App development you have achieved with Web API's with the help of Angular 7, Could you share a sample app to us.

    It's we be helpful to start with working source code.

     

    Thanks and Regards,

    Vamsi K

    0
    Comment actions Permalink
  • Jesús Giménez

    Hello, I can't share Angular App code because have a lot of components and can't make it public because is company work, but if you ask for Android Webview then I post the basis:

    public class MainActivity extends AppCompatActivity {

    private static final int MY_PERMISSIONS_REQUEST = 100;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    WebView myWebView = new WebView(this);

    WebSettings webSettings = myWebView.getSettings();
    webSettings.setLoadsImagesAutomatically(true);
    webSettings.setAllowContentAccess(true);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setPluginState(WebSettings.PluginState.ON);
    webSettings.setMediaPlaybackRequiresUserGesture(false);

    /* CUSTOM USER AGENT */
    webSettings.setUserAgentString("hcapp");

    myWebView.setWebViewClient(new WebViewClient(){
    public void onReceivedError(WebView webView, int errorCode, String description, String failingUrl) {
    try {
    webView.stopLoading();
    } catch (Exception e) {
    }

    if (webView.canGoBack()) {
    webView.goBack();
    }

    webView.loadUrl("about:blank");
    AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
    alertDialog.setTitle("Error de conexión");
    alertDialog.setMessage("Comprueba tu conexión a internet y vuelve a intentarlo.");
    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Recargar", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
    finish();
    startActivity(getIntent());
    }
    });

    alertDialog.show();
    super.onReceivedError(webView, errorCode, description, failingUrl);
    }
    });

    myWebView.setWebChromeClient(new WebChromeClient(){
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @Override
    public void onPermissionRequest(final PermissionRequest request) {
    request.grant(request.getResources());
    }
    });

    // Here, thisActivity is the current activity
    if (ContextCompat.checkSelfPermission(MainActivity.this,
    Manifest.permission.READ_CONTACTS)
    != PackageManager.PERMISSION_GRANTED) {

    // Should we show an explanation?
    if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,
    Manifest.permission.READ_CONTACTS)) {

    // Show an expanation to the user *asynchronously* -- don't block
    // this thread waiting for the user's response! After the user
    // sees the explanation, try again to request the permission.

    } else {

    // No explanation needed, we can request the permission.

    ActivityCompat.requestPermissions(MainActivity.this,
    new String[] {
    android.Manifest.permission.RECORD_AUDIO,
    android.Manifest.permission.MODIFY_AUDIO_SETTINGS,
    android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
    android.Manifest.permission.CAMERA
    }, MY_PERMISSIONS_REQUEST);

    }
    }
    setContentView(myWebView);
    myWebView.loadUrl("yourWebAppURL");

    }
    }

    After this base code I implemented file send and download (blob to data URI and then convert to file).

     

    Told me if you need some help, regards,

    Jesús.

    0
    Comment actions Permalink

Please sign in to leave a comment.

Still can't find what you need?

  • Contact Us

    Do you have any question about Rainbow? Leave us a message to get more information.

    Contact
  • Ask the Community

    Do you need help? Ask your questions to the Community and get answers from other Rainbow users.

    Post message