Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Readers > Android Devices > Android Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 01-22-2011, 09:32 AM   #1
askndaer
Junior Member
askndaer began at the beginning.
 
Posts: 1
Karma: 10
Join Date: Jan 2011
Device: none
Webview with authorized

Hi

I have built app that display asp pages using WebView but some of the page want the authentication (Username ,Password ) to login I want whan i press login button it will display the page after login in Webview page

Please Help

this is the asp page
Welcome to UCSI eAdvantage

This is my Code:::


package cc.tav;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity ;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.http.HttpHost;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

public class cc extends Activity {
/** Called when the activity is first created. */
WebView mWebView;
TextView tt;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

String returnValue = "";

try {
HttpHost hh = new HttpHost("www.ucsi.edu.my");

HttpClient httpclient = new DefaultHttpClient();

HttpPost post = new HttpPost(new URI(
"http://www.ucsi.edu.my/advantage/new/check_user.asp"));

post.setHeader("Content-Type", "application/x-www-form-urlencoded");

// Add data we're going to POST & assign data to the HttpPost
// object.
List<NameValuePair> nvPairs = new ArrayList<NameValuePair>(2);
nvPairs.add(new BasicNameValuePair("txtUserID", "123456"));
nvPairs.add(new BasicNameValuePair("txtPassword", "123456"));
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nvPairs,
"UTF-8");
post.setEntity(formEntity);

// Execute POST
HttpResponse response = httpclient.execute(post);

// Generate String from response.
HttpEntity entity = response.getEntity();
returnValue = EntityUtils.toString(entity);


System.out.println(returnValue);

mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
// mWebView.loadUrl("http://www.ucsi.edu.my/ses/");

mWebView.loadData(returnValue, "text/html/xhtml/xml",
"gzip/deflate");

mWebView.setWebViewClient(new WebViewClient());

} catch (UnsupportedEncodingException e) {
e.printStackTrace();

} catch (ClientProtocolException e) {
e.printStackTrace();

} catch (IOException e) {
e.printStackTrace();

} catch (URISyntaxException e) {
e.printStackTrace();

}

System.out.println(returnValue);
}

public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
askndaer is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Not an authorized user? andrea t Barnes & Noble NOOK 5 01-18-2011 10:05 PM
Can 2 e-readers be authorized on one computer? jazz General Discussions 4 12-02-2010 08:02 AM
PRS-505 Viewing Authorized Devices Nivek Sony Reader 2 06-15-2010 02:22 AM
Not staying authorized sweetnlov Sony Reader 6 03-06-2010 11:48 PM
Not authorized for the eBook Store jpbergmans Sony Reader 6 04-26-2009 06:19 PM


All times are GMT -4. The time now is 02:12 AM.


MobileRead.com is a privately owned, operated and funded community.