我正在android上编写一个应用程序,显示来自IP摄像头的传输,这个camarea是一个D-Link,为了查看我去ip的传输:192.168.1.4/MJPEG.CGI?.mjpeg
它在我的导航器中工作,但要访问它,我需要一个通过 Javascript 提示为管理员复合帐户:
在此处输入图像描述
在我的 android 应用程序中,我使用的是带有片段的 Navigation Drawable,并且我已经指定了一个用于传输的片段,我使用的是 WebView,我的片段的 XML:
<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>
这很简单,我的按钮是将允许的 url 加载到我的 EditText 中,到我的 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;
}
}
}
我一直在用其他 Js 文件进行测试以尝试获取警报或确认警报,但我无法得到它。
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>
对于带有 Alert Desition 的示例,我尝试使用 onJsConfirm 但没有发生任何事情,而且给我传输的页面更少,曾经对登录做出否定回答:
我真的需要帮助,我查看了很多页面和视频以找到解决方法,但我没有答案。请问有人可以帮助我吗?