Black video while working with ip camera in webview android - android

I want to display video of IP camera in android application.
For this I am using a webview.
In the navigator of my smartphone I can see and control the web camera but in the webview video is always black and controls don't work.
This is the source code of my activity :
public class MainActivity extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
webView = (WebView) findViewById(R.id.vision);
webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new myWebViewClient());
webView.setHttpAuthUsernamePassword("http://192.168.1.2/", null, "admin", null);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginState(PluginState.ON);
webView.loadUrl("http://192.168.1.2/");
}
public class myWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
I got this error in the log ![enter image description here][1]
web console uncaught reference error resolution is not defined.

If you are trying to play a HTML5 video (from your IP camera) in a WebView, this previous answer from another question might help you:
WebView and HTML5 <video>

Related

Force Android WebView to open external links in default browser

I am using the following code found on stackoverflow to make an app for my website.
It works, the website loads, but all links are loading inside the app.
I dont want links like facebook, youtube or any other external links to open inside my app.
How can I open external links outside my webview app ?
I am new to android coding, so if you can edit my code and post a full example answer, it will be great help.
public class MainActivity extends AppCompatActivity {
private WebView mywebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mywebView=(WebView) findViewById(R.id.webview);
mywebView.setWebViewClient(new WebViewClient());
mywebView.loadUrl("https://www.sitename.com");
WebSettings webSettings=mywebView.getSettings();
webSettings.setJavaScriptEnabled(true);
}
public class mywebClient extends WebViewClient{
#RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
if((String.valueOf(request.getUrl())).contains("facebook")) {
view.loadUrl(String.valueOf(request.getUrl()));
} else {
Intent intent = new Intent(Intent.ACTION_VIEW, request.getUrl());
view.getContext().startActivity(intent);
}
return true;
}
}

My webview is opening the webpage in the default browser

So I just implemented a simple webview application in which i was loading the stackoverflow main page. Earlier it was working just fine but now as I click on some link it opens that link in the default browser. I have implemented and override the shouldoverrideUrlLoading method by creating my custom webViewClient class.
I know that there are various question ask like these but I am writing this question only because they don't work for me.
public class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(Uri.parse(url).getHost().endsWith(".com"))
return false;
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(url));
view.getContext().startActivity(intent);
return true;
}
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new MyWebViewClient());
final customEditText editText = findViewById(R.id.urlEditText);
Button button = findViewById(R.id.enterButtonId);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
webView.loadUrl("https://"+editText.getText().toString().trim().toLowerCase());
}
});
}
You can use this:
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("url");
Just implement the web client and set it before loadUrl. The simplest way is:
WebView.setWebViewClient(new WebViewClient());
So When I was reading a tutorial https://www.journaldev.com/9333/android-webview-example-tutorial in this it is given that when shouldOverrideUrlLoading( ) method provides false then it url opens in our webview and if it returns true, then it will not load the page at all. So I think that earlier my code was working was because I was opening .com extensioned websites but when i open other extension website then it redirect to the default browser.

Flash is not loading in Web view in Android

I am trying to Load a webview in Android. Where web page have a swf file but it is not loading. I know there are many question and answer on same topic but no one helped me.
I have already targeted it version 11. And I have put android:hardwareAccelerated="true" too in manifest.xml file.
My code is here-
public class MainActivity extends Activity {
private WebView mWebView;
String url="http://mypages.com/Ch_001/ScoPage.html";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.webView);
mWebView.setKeepScreenOn(true);
WebSettings settings = mWebView.getSettings();
settings.setPluginState(PluginState.ON);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.setInitialScale(100);
// wbView.getSettings().setUseWideViewPort(true);
mWebView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
mWebView.setWebViewClient(new MyWebViewClient());
}
private class MyWebViewClient extends WebViewClient {
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler,
SslError error) {
Log.e("Error VAGARO", error.toString());
handler.proceed();
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
}
}
After one week struggle I got a Flash player from Macromedia, which works for me.
You can search in Google for-"Flash Player 11.1.for Android 4.0 - Macromedia - Adobe" or install APK from this link.
Install this apk in your Android device.
And when you will open it, it will ask for choose default browser.
Choose any browser which support Flash (UC-Browser, Chrome etc).
Now run your any application it will load your Flash video.
Add this code:
webview.getSettings().setPluginsEnabled(true);
add mWebView.loadUrl(url);in onCreate

When I Embed a website (wordpress blog) on my android app it opens in another browser?

I just start android developing and I want to embed my website in the app.
When I want to open "http://www.google.com" , webpage opens in My app, but when I change address to my blog it wants to open it on external browser.
This is My activity code that I used to embed my site!
public class WebPage extends Activity {
#SuppressLint("SetJavaScriptEnabled") #Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_page);
//web view start
WebView med = (WebView) findViewById(R.id.webView1);
med.getSettings().setJavaScriptEnabled(true);
med.getSettings().
med.loadUrl("http://www.mediratour.com");
}
}
My webpage based on wordpress, I don't know if I have to change settings to prevent using external browser and opens it in My app.
Thanks
// Set this on your web view.
webView.setWebViewClient(new WebClient());
// Create this class.
public class WebClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(final WebView webView, final String url) {
webView.loadUrl(url);
return true;
}
}
I think it helps.

Problem in using WebView?

I have created a page which has link to a page of a website. So for showing that on I have used a WebView and it works fine.
My Problem is that when I click on any link given on that webpage, the link opens in phone's default browser view. But I want all the links to be opened in my created WebView.
Have I made any mistake or it is right..
Please Help Me
My code is as follows...
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Log.e("------------", ".........................................................................................");
setContentView(R.layout.terms_of_use_web_view_page);
btn_back = (Button) findViewById(R.id.terms_of_use_button_back);
btn_back.setOnClickListener(this);
webview = (WebView)findViewById(R.id.terms_of_use_webview);
webview.getSettings().setJavaScriptEnabled(false);
webview.loadUrl("http://www.oomphlink.com/terms-of-use/");
}
Try specifying your own WebViewClient:
WebView webView = (WebView)findViewById( R.id.terms_of_use_webview );
webView.setWebViewClient( new WebViewClient()
{
#Override
public boolean shouldOverrideUrlLoading( WebView view, String url )
{
view.loadUrl( url );
return true;
}
});
To further understand why this is necessary have a look at the documentation for the shouldOverrideUrlLoading method.
wv.setWebViewClient(new MyWebViewClient());
public class MyWebViewClient extends WebViewClient{
}
link for more info...

Categories

Resources