WebView Android loading Angular 7 app didn't load #minivideo at first time
Hello,
I developed an angular 7 app with webRTC functionality and now i would like to create an Android App with that responsive WebApp.
I have all working good, page interacts correct, but when I launch videocall can only see the incoming video from other part, my own video don't show (at least at first time).
In angular app when call state is active I invoke this methods:
showLocalVideo()
and showRemoteVideo(call)
Show local video don't work at first time, but if I make a button with wrapper function containing this method and pulse it, video appears. At first instead of video appear Android placeholder with player image.
I've been looking this for some days and I can't make it work, I tried invoking method in other parts of code, or create a timeout function to call automatically another time after x seconds call active, any of that didn't work.
It's strange, if I manually call the method clicking button it shows camera, but if I do it programatically with timeout or natural way didn't happen anything.
I post it because maybe anyone you know how to fix it, it has to be some minor change in code or something I missed. I'm not Android developer so I don't know how to fix it, thats the reason I'm trying webapp instead of native app.
Thanks in advance,
Regards!
-
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
-
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
-
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.
Please sign in to leave a comment.
Comments
4 comments