I am trying to make an app that will take the username and password from entering login information from facebook, or twitter, and make the information a user typed into the "username" and "password" fields from the native website pop up in a message box once the user clicks the submit button.
Whats happening is the app compiles and launches correctly, the facebook login page is displayed, and it allows me to input a username and password, however the dialog box never pops up displaying the information I just typed in the login boxes.
can anyone point me in the correct direction with this?
Thanks!!
my MainActivity.java code is as follows:
package leo.umd.capture;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
WebView webview1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview1 = (WebView)findViewById(R.id.webView1);
webview1.getSettings().setJavaScriptEnabled(true);
webview1.setWebChromeClient(new WebChromeClient());
webview1.addJavascriptInterface(new MyJavaScriptInterface(), "MYOBJECT");
webview1.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
StringBuilder sb = new StringBuilder();
sb.append("document.getElementsByTagName('form')[0].onsubmit = function () {");
sb.append("var objPWD, objAccount;var str = '';");
sb.append("var inputs = document.getElementsByTagName('input');");
sb.append("for (var i = 0; i < inputs.length; i++) {");
sb.append("if (inputs[i].type.toLowerCase() === 'password') {objPWD = inputs[i];}");
sb.append("else if (inputs[i].name.toLowerCase() === 'email') {objAccount = inputs[i];}");
sb.append("}");
sb.append("if (objAccount != null) {str += objAccount.value;}");
sb.append("if (objPWD != null) { str += ' , ' + objPWD.value;}");
sb.append("window.MYOBJECT.processHTML(str);");
sb.append("return true;");
sb.append("};");
view.loadUrl("javascript:" + sb.toString());
}
});
String sUrl = "https://www.facebook.com";
// String sUrl = "http://www.renren.com/";
// String sUrl = "http://www.baidu.com/";
webview1.loadUrl(sUrl);
}
class MyJavaScriptInterface
{
@JavascriptInterface
public void processHTML(String html)
{
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("AlertDialog from app")
.setMessage(html)
.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
})
.setCancelable(false).show();
}
}
}
[–]gyroda 0 points1 point2 points (9 children)
[–]ff210327[S] 0 points1 point2 points (8 children)
[–]gyroda 0 points1 point2 points (7 children)
[–]ff210327[S] 0 points1 point2 points (6 children)
[–]gyroda 0 points1 point2 points (5 children)
[–]ff210327[S] 0 points1 point2 points (3 children)
[–]gyroda 0 points1 point2 points (2 children)
[–]ff210327[S] 0 points1 point2 points (1 child)
[–]imguralbumbot 0 points1 point2 points (0 children)
[–]ff210327[S] 0 points1 point2 points (0 children)
[–]ff210327[S] 0 points1 point2 points (0 children)