I'm writing an application on android that shows a transmition from an Ip Camera, this camarea is a D-Link, for see the transmission I go to the ip: 192.168.1.4/MJPEG.CGI?.mjpeg
and it works in my navigator, but to access it asks me for an account for the admin compound by a Javascript Prompt:
enter image description here
In My android application I'm using a Navigation Drawable with fragments and I have designated an fragment for the transmition, I'm using a WebView, XML of my fragment:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.promindsoft.theprodigyeye.MainFragment">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:hint="Enter Text"
android:focusable="true"
android:textColorHighlight="#ff7eff15"
android:textColorHint="#f23012"
android:layout_marginTop="46dp"
android:layout_below="@+id/imageView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/imageView"
android:layout_alignEnd="@+id/imageView" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/human_greeting"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter"
android:id="@+id/button"
android:layout_alignTop="@+id/editText"
android:layout_toRightOf="@+id/imageView"
android:layout_toEndOf="@+id/imageView" />
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/webView"
android:layout_below="@+id/button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
It's very simple, my button is to load the url it is allowed into my EditText, into my MainFragment.java:
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;
/**
* A simple {@link Fragment} subclass.
*/
public class MainFragment extends Fragment {
Button b1;
EditText ed1;
private WebView mWebView ;
public MainFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_main, container, false);
b1=(Button)view.findViewById(R.id.button);
ed1=(EditText)view.findViewById(R.id.editText);
ed1.setText("http://192.168.1.76/javas.html");
mWebView =(WebView)view.findViewById(R.id.webView);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getActivity(),"Okey",Toast.LENGTH_SHORT).show();
String url = ed1.getText().toString();
WebSettings webSettings = mWebView.getSettings();
webSettings.setPluginState(WebSettings.PluginState.ON);
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
mWebView.loadUrl(url);
mWebView.setWebViewClient(new MyBrowser());
}
});
return view;
}
private class MyBrowser extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView webview, String url)
{
webview.setWebChromeClient(new WebChromeClient() {
private View mCustomView;
@Override
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
AlertDialog.Builder b = new AlertDialog.Builder(getContext())
.setTitle(view.getTitle())
.setMessage(message)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
result.confirm();
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
result.cancel();
}
});
b.show();
// Indicate that we're handling this manually
return true;
}
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result)
{
new AlertDialog.Builder(view.getContext()).setMessage(message).setCancelable(true).show();
result.confirm();
return true;
}
@Override
public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback)
{
// if a view already exists then immediately terminate the new one
if (mCustomView != null)
{
callback.onCustomViewHidden();
return;
}
}
});
webview.loadUrl(url);
return true;
}
}
}
I've been doing test with anothers Js files to try to get Alerts or Confirm Alerts but I can't get it.
JS:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
//document.write("Shit")
alert("Hola")
var x;
if (confirm("Press a button!") == true) {
x = "You pressed OK!";
} else {
x = "You pressed Cancel!";
}
document.write(x);
var person = prompt("Please enter your name");
if (person != null) {
document.write("Hello " + person + "! How are you today?");
}
</script>
</head>
<body>
<h1>Okey</h1>
</body>
</html>
for the example with an Alert Desition I tried with onJsConfirm but nothing happened, and less with the page that give me the transmition, ever taken a negative answer about the login:
I need really help, I've looking around a lot of pages and videos to find the way to do it, but I dont have answer. Please someone can help me?