Search Results

Search found 4 results on 1 pages for 'datguywhowanders'.

Page 1/1 | 1 

  • Maintain cookie session in Android

    - by datguywhowanders
    Okay, I have an android application that has a form in it, two EditText, a spinner, and a login button. The user selects the service from the spinner, types in their user name and password, and clicks login. The data is sent via POST, a response is returned, it's handled, a new webview is launched, the html string generated form the response is loaded, and I have the home page of whatever service the user selected. That's all well and good. Now, when the user clicks on a link, the login info can't be found, and the page asks the user to login again. My login session is being dropped somewhere, and I'm not certain how to pass the info from the class that controls the main part of my app to the class that just launches the webview activity. The on click handler from the form login button: private class FormOnClickListener implements View.OnClickListener { public void onClick(View v) { String actionURL, user, pwd, user_field, pwd_field; actionURL = "thePageURL"; user_field = "username"; //this changes based on selections in a spinner pwd_field = "password"; //this changes based on selections in a spinner user = "theUserLogin"; pwd = "theUserPassword"; List<NameValuePair> myList = new ArrayList<NameValuePair>(); myList.add(new BasicNameValuePair(user_field, user)); myList.add(new BasicNameValuePair(pwd_field, pwd)); HttpParams params = new BasicHttpParams(); DefaultHttpClient client = new DefaultHttpClient(params); HttpPost post = new HttpPost(actionURL); HttpResponse response = null; BasicResponseHandler myHandler = new BasicResponseHandler(); String endResult = null; try { post.setEntity(new UrlEncodedFormEntity(myList)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } try { response = client.execute(post); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { endResult = myHandler.handleResponse(response); } catch (HttpResponseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } List cookies = client.getCookieStore().getCookies(); if (!cookies.isEmpty()) { for (int i = 0; i < cookies.size(); i++) { cookie = cookies.get(i); } } Intent myWebViewIntent = new Intent(MsidePortal.this, MyWebView.class); myWebViewIntent.putExtra("htmlString", endResult); myWebViewIntent.putExtra("actionURL", actionURL); startActivity(myWebViewIntent); } } And here is the webview class that handles the response display: public class MyWebView extends android.app.Activity{ private class MyWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.web); MyWebViewClient myClient = new MyWebViewClient(); WebView webview = (WebView)findViewById(R.id.mainwebview); webview.getSettings().setBuiltInZoomControls(true); webview.getSettings().setJavaScriptEnabled(true); webview.setWebViewClient(myClient); Bundle extras = getIntent().getExtras(); if(extras != null) { // Get endResult String htmlString = extras.getString("htmlString"); String actionURL = extras.getString("actionURL"); Cookie sessionCookie = MsidePortal.cookie; CookieSyncManager.createInstance(this); CookieManager cookieManager = CookieManager.getInstance(); if (sessionCookie != null) { cookieManager.removeSessionCookie(); String cookieString = sessionCookie.getName() + "=" + sessionCookie.getValue() + "; domain=" + sessionCookie.getDomain(); cookieManager.setCookie(actionURL, cookieString); CookieSyncManager.getInstance().sync(); } webview.loadDataWithBaseURL(actionURL, htmlString, "text/html", "utf-8", actionURL); } } } I've had mixed success implementing that cookie solution. It seems to work for one service I log into that I know keeps the cookies on the server (old, archaic, but it works and they don't want to change it.) The service I'm attempting now requires the user to keep cookies on their local machine, and it does not work with this setup. Any suggestions?

    Read the article

  • Submit form with POST data in Android app

    - by datguywhowanders
    I've been searching the web for a way to do this for about a week now, and I just can't seem to figure it out. I'm trying to implement an app that my college can use to allow users to log in to various services on the campus with ease. The way it works currently is they go to an online portal, select which service they want, fill in their user name and pwd, and click login. The form data is sent via post (it includes several hidden values as well as just the user name and pwd) to the corresponding login script which then signs them in and loads the service. I've been trying to come at the problem in two ways. I first tried a WebView, but it doesn't seem to want to support all of the html that normally makes this form work. I get all of the elements I need, fields for user and pwd as well as a login button, but clicking the button doesn't do anything. I wondered if I needed to add an onclick handler for it, but I can't see how as the button is implemented in the html of the webview not using a separate android element. The other possibility was using the xml widgets to create the form in a nice relative layout, which seems to load faster and looks better on the android screen. I used EditText fields for the input, a spinner widget for the service select, and the button widget for the login. I know how to make the onclick and item select handlers for the button and spinner, respectively, but I can't figure out how to send that data via POST in an intent that would then launch a browser. I can do an intent with the action url, but can't get the POST data to feed into it. Anyone have any suggestions?

    Read the article

  • Display HttpResponse (string from Handler) in new WebView

    - by datguywhowanders
    I have the following code in a form's submit button onClickListener: String action, user, pwd, user_field, pwd_field; action = "theURL"; user_field = "id"; pwd_field = "pw"; user = "username"; pwd = "password!!"; List<NameValuePair> myList = new ArrayList<NameValuePair>(); myList.add(new BasicNameValuePair(user_field, user)); myList.add(new BasicNameValuePair(pwd_field, pwd)); HttpParams params = new BasicHttpParams(); HttpClient client = new DefaultHttpClient(params); HttpPost post = new HttpPost(action); HttpResponse end = null; String endResult = null; try { post.setEntity(new UrlEncodedFormEntity(myList)); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { HttpResponse response = client.execute(post); end = response; } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } BasicResponseHandler myHandler = new BasicResponseHandler(); try { endResult = myHandler.handleResponse(end); } catch (HttpResponseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } How can I take the resulting string (endResult) and start a new activity using an intent that will open webview and load the html?

    Read the article

  • Android Icon Duplicates in Application Dock

    - by datguywhowanders
    For some odd reason, my project is generating two icons, same name, launches the same project, in the app drawer. I can't figure out what is causing this. Does anyone have any suggestions? Link to screenshot The M in the white circle is my default icon. If you view the screenshot, you'll see it appears twice. I've checked the applications area, and it is only installed once.

    Read the article

1