How to pass String argument? - android

I am having problem while passing string argument using javascript injection in my android application..
I am using the
webview.loadUrl("javascript:(function() { " +
" document.getElementById()
, but m not getting the exact output..
I want to connect my login form (locally created) with website, so that whenever user enter userID & password in my login form, it automatically get added to that website login form..
please help me with some simplified sample code.

JavaScript is not Enabled as Default for the webview . you have to enable it like below
webview.getSettings().setJavaScriptEnabled(true);

Related

Get data from text box of a website using WebView

In my application, I am showing our own e-commerce website in WebView. In that, I have username and password textboxes. I want to get username of text data while he is entering and want to store it in my file. I do not have any control of website(Login page). It is completely build by third party How can I achieve this ? please help.
Thank you in advance.
You can use JavaScript for load data from the webView.
I use following JS code for load html from the webView
JS_PARSER = "(function() { return ('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>'); })();"
webview.getSettings().setJavaScriptEnabled(true);
webView.evaluateJavascript(JS_PARSER, <callback for handle response with html>);
evaluateJavascript docs
And try to load data from the html.
As second way you can make JS function for load text from the textBoxs. And execute the function for each textBox.
JS function for load data from textBox:
function myFunction(){
return document.getElementById("f6").value;
}
Android code for second way:
String LOAD_FUN = function getValue(){ return document.getElementById('%s').value; }();
webView.evaluateJavascript(String.format(LOAD_FUN, "<String with textBoxId>"), <callback for handle textBox value>)

How to fill fields in a webview gettings data from remote URL

I am new developer in Android, I would to like to fill fields in a web view getting page from remote URL.
My application used shared preferences to store username/password to fill automatically fields username/password belongs to a login page. This login page is retrieved from a remote url and dispayed in webview.
How to fill the fields username/password?
Any suggestion can help me.
I already used javascript and does not work.
Regards
Try this one
webView.loadUrl("javascript: {" +
"document.getElementById('username').value = '"+username +"';" +
"document.getElementById('password').value = '"+password+"';" +
"var frms = document.getElementsByName('loginForm');};");

Twitter call back url not working in android

Now i try to Implement Twitter Integration in android using twitter4j library.Few months back I successfully implemented this using a dummy call back url like "PicPuzzle://tkxel".
But now Twitter changes its scheme and now not allow to create application with dummy URL.
Now the problem is after authentication It redirect to callbackurl But not return to application.
I specify the same url in application and registration page. I refered Problem in Callback in Twitter in Android and How I can call back in Android using OAuth for Twitter?. But these solutions are now not working because now twitter not allow to create application with dummy URL. Please help me to solve this problem.
Follow below steps:
Go to Twitter Apps: https://apps.twitter.com/
Then, Go to your app.
Go to Settings Tab
In section "Callback URLs", add the below line:
twittersdk://
Click button "Update Settings" at the bottom. That's it.
Hope this works!
Create your own WebViewClient subclass.
Override shouldOverrideUrlLoading(WebView view, String url) method.
In shouldOverrideUrlLoading(), check if url.startsWith(YOUR_CALLBACK_URL) is true.
If true, retrieve "oauth_verifier" parameter from the URL and return true (true from shouldOverrideUrlLoading() prevents the WebView instance from loading the URL).
Get an access token using the value of the parameter obtained in the step 4.
Your application can get control back from the WebView instance after the step 4.
If the above steps sound cumbersome, try TwitterOAuthView. Its usage is very simple. Just call
view.start(CONSUMER_KEY, CONSUMER_SECRET, CALLBACK_URL, true, listener);
and receive the result via TwitterOAuthView.Listener interface defined as below.
void onSuccess(TwitterOAuthView view, AccessToken accessToken);
void onFailure(TwitterOAuthView view, TwitterOAuthView.Result result);
If true is given to TwitterOAuthView.start() method as the forth argument, TwitterOAuthView does not access the callback URL, and I think this behavior is what you want to implement. The source code, TwitterOAuthView.java, may be of help.

How to access querystrings from URL in android using appcelerator

I am implementing OAUTH in android using appcelerator. login page is redirecting to response page with token appended to query string e.g. http://mysite.com?access_token="token"
So I need to fetch this query string using appcelerator.
I have used Ti.App.getArguments()
but this api is only working for ios not for android.
Is there any api available for fetching query string in appcelerator that works in android??
Add an event listener to the webview like so:
webview.addEventListener('load', function(e){
var url = e.url.split('?');
var urlParams = url[1];
});
The variable urlParams will contain a string that looks like param1=value1&param2=value2 so from there you just need to split them up and find the access_token param.

Launch a background web search

I am trying to launch a websearch using data input from a user. The data is input through TextEdit boxes. Upon submission of the data, i would like my program to: 1) search for a specific webpage based on the user input 2)Find specific elements at the webpage 3) Display the webpage.
Here is an example:
User Input (in a non browser/webview page)
1) Store Name: Macey's 2)Zip Code: 77471
In the background my program will:
1) Find the Macey's website
2) Find the store nearest zip code 77471
3) Load the Web page for the store nearest zip code 77471
Obviously there is a lot of error handeling, exceptions, ect that would go along with this. For the sake of making this example "easy" lets pretend that 1) A the Macey's main page exists 2)A sperate page for the 77471 store exists. 3)There is a link to the 77471 store on the Macey's main page.
I have the code for getting the user input variables and i know how to launch the webview. What i dont know how to do is to search for the Macy's home page, then find the link i am looking for on the homepage and navigate to it. Loading the webview is not the problem. Find the data is.
Below is my current code. Right now i am setup so that the user will navigate to the webpage they are looking for but i would rather handle the searching for them, if it is possible.
public void InitializeWebView(){
portal = (WebView)findViewById(R.id.web_Portal);
WebSettings Settings = portal.getSettings();
Settings.setSavePassword(false);
Settings.setSaveFormData(false);
Settings.setJavaScriptEnabled(true);
Settings.setSupportZoom(true);
Settings.supportZoom();
portal.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
}
public void searchAndShow(String Store, String zip){
portal.loadUrl("http://www.google.com");
}
You can get search result in JSON format from google using their API. Here is a nice example in JAVA. Just don't use key parameter until you do not have a vlid key.

Categories

Resources