0
まあまあですが、私はGoogleのボレーで簡単なログインを作成しました。 ユーザーがログに記録されたら、彼はいくつかのアクションを実行するために、クッキーを追跡する必要があります。 私はこの機能でクッキーを設定します。Androidのボレーユーザーがクッキーでログインしているようにする
PersistentCookieStoreはこれですprivate boolean setUpCookies(){
boolean ris;
cookieManager = new CookieManager(new PersistentCookieStore(getApplicationContext()), CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(cookieManager);
SharedPreferences preferences = getSharedPreferences(PersistentCookieStore.class.getName(), MODE_PRIVATE);
String session_cookie = preferences.getString("session_cookie",null);
if(session_cookie != null && !session_cookie.isEmpty()){
Log.d(TAG,session_cookie);
ris = true;
}else{
ris = false;
}
return ris;
}
:私は、サーバーのPHPを編集することはできませんので
@Override
public void onResponse(String response) {
JsonParser parser = new JsonParser();
JsonElement element = parser.parse(response);
if (element.isJsonArray()) {
try{
JsonArray array = element.getAsJsonArray();
JsonObject tmp = array.get(0).getAsJsonObject();
if(setUpCookies()){
Toast.makeText(getApplicationContext(), "Login OK", Toast.LENGTH_LONG).show();
Intent myIntent = new Intent(MainActivity.this, PostLogin.class);
startActivity(myIntent);
}else{
Toast.makeText(getApplicationContext(), "Could not set up cookies!", Toast.LENGTH_LONG).show();
}
}catch (Exception e){
VolleyLog.d(e.getMessage());
}
} else if (element.isJsonObject()) {
JsonObject object = element.getAsJsonObject();
Toast.makeText(getApplicationContext(), "Error! " + object.get("error").getAsString(), Toast.LENGTH_LONG).show();
}
showProgress(false);
}
:私はこれを持ってonResponse私のボレーで次にsource
ページ、私はこれを正しく行っているのだろうか、私はエミュレータでアプリケーションを起動すると、私はログインしてOK応答を取得してから、Androidデバイスモニタ私はその設定を削除するので、クッキーaセットしないでください! 私は自分自身を説明できることを願っています。
通常のようにセッションCookieをアプリケーションに保存しようとしていますかユーザーのセッションを保存するWebブラウザで? – Omkar
さて、私はアプリを開発していますが、単一のWebブラウザは使用されません – Vesco