3

I'm using ksoap2 for web service method calls. First, the user must login. I want others method in web service could only be call after login. But i can not do that. Because I don't have any session in web service. I don't know how to do that in web service. How the web service know that user have already login in the android apps? Do you have any ideas, session or cookies :(. Thanks for reading my question. Here is my code in web service

public class Login {
String message;
Connection conn;
String url;
ResultSet rs;
Statement stmt;
public String login(String username, String password) {
    try {
        Class.forName("org.postgresql.Driver");
        url = "jdbc:postgresql://localhost:5432/FirstDB";
        conn = DriverManager.getConnection(
                url, "postgres",
                "root");
        stmt = conn.createStatement();
        rs = stmt.executeQuery("SELECT * From account Where username = '"+ username + "'and password = '" + password +"'");
        if ( rs.next() ) {
            message = "true";
        } else {
            message = "false";
        }
    } catch (Exception e) {
        System.err.println("Got an exception! ");
        System.err.println(e.getMessage());
    }
    return message;
}

public String Test() {
    if(message.equals("true")) 
    {
        return "abc";
    }
    return "bdf";
}

}

In the android app. First I call the method login(), then method Test(). The result always be "bdf".

Black2910
  • 133
  • 3
  • 9

1 Answers1

1

To maintain sessions in the Android Application you can use shared preferences.

For example see Android User Session Management using Shared Preferences

or you can try in this way Maintaining session in android ( application stay authenticated on the server side)

Community
  • 1
  • 1
Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78
  • Thank you but I want to keep the session in the web service, not the Shared Preferences in the android apps :(. Do you have any other ideas? – Black2910 Oct 25 '12 at 04:02
  • [link](http://stackoverflow.com/questions/11520099/how-to-keep-session-in-android) The question in this topic is similar to my problem. But the answer is no clear. And I don't know how to create a session in web service after the android apps have connected. – Black2910 Oct 25 '12 at 04:04
  • I think [this](http://metatroid.com/article/Android:%20handling%20web%20service%20authentication) link may help you. – Ram kiran Pachigolla Oct 25 '12 at 04:09
  • This link is just about the android apps. Can you explain the flow between the android apps and web service more specific. I think the flow between them: First the android apps login, then the web service create cookies or session and the android apps can use other method in the web service. Is that right? – Black2910 Oct 25 '12 at 04:35