私はAndroid 2.2で作業しています。ユーザーがアプリケーションに入ると、提供されるデフォルトのオーディオファイルを使用することができます。登録ユーザーは一度だけ認証されるべきです
ボタンをクリックすると、ログインページに移動します。登録されていないユーザは、自分自身を登録し、再度ユーザ名とパスワードでログインします。ユーザ名とパスワードでログインするとn個のオーディオファイルをサーバからダウンロードすることを許可されている。
だから私が習得したいのは、ユーザーが登録ユーザーでログインしてアプリケーションを終了した後ですが、もう一度登録したユーザーがいくつかのファイルをダウンロードしたいのであれば、彼はユーザー名とパスワードを入力する必要はありませんユーザー。
これを達成するには?
コード登録ユーザーログインする:あなたは、あなたがダウンロードを開始したときに、それがsettedされる.IF、あなたがそうでなければ、オープンログイン/ registartionページ何でもあなたを続けることができ、あなたのアプリケーションのためのSharedPreferenceを使用して、それを確認することができます
ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>();
nvp.add(new BasicNameValuePair("userid", userid.getText().toString()));
nvp.add(new BasicNameValuePair("password", password.getText().toString()));
String un = userid.getText().toString();
String pass = password.getText().toString();
System.out.println("user name is " + un);
System.out.println("password is " +pass);
// Log.e(""+sid.getText().toString(),"0");
// Log.e(""+sname.getText().toString(),"0");
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://mywebsite.com/login.php");
httppost.setEntity(new UrlEncodedFormEntity(nvp));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch(Exception e){
Log.e("log_tag", "Error in http connection"+e.toString());
}
try {
BufferedReader bf = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
sb = new StringBuilder();
sb.append(bf.readLine()+ "\n");
String line="0";
while ((line = bf.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
System.out.println("value of result " +result);
if(result.contains(auth)){
System.out.println("username and password is correct");
Intent authorised = new Intent(Login.this,BrowseFiles.class);
startActivity(authorised);
}else{
System.out.println("incorrect wrong wrong wrong");
error.setText("Incorrect username and password");
}
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
ユーザー名とパスワードを保存する必要がありますか?あなたは私にその例を教えてください。 – Goofy
リンクを参照すると、sharedPreferenceを使用して編集する方法も表示されます。 –
ボタンを押してコンテンツをダウンロードする前に、ユーザーが認証されたときに編集してください。 .. –