How Open A New Activity On A Onresponse Of Volley
I try to open a new activity on a onResponse of Volley. But I have no idea of what parameters I can use. Indeed my Volley request is on another class and, I think I need to pass t
Solution 1:
publicvoidTokenRequest(final Context context,final String login, final String password){
final StringRequest stringRequest = newStringRequest(com.android.volley.Request.Method.POST, ressources.urlToken,
newResponse.Listener<String>() {
@OverridepublicvoidonResponse(String response) {
Log.e("onResponse", response);
pref = newPrefManager(context);
pref.storeIsConnect(true);
try{
JSONObject rep = newJSONObject(response);
//stockage des données
pref.storeScope(rep.getString("scope"));
pref.storeTokenType(rep.getString("token_type"));
pref.storeAccessToken(rep.getString("access_token"));
pref.storeRefreshToken(rep.getString("refresh_token"));
pref.storeExpiresIn(rep.getString("expires_in"));
}catch (JSONException e) {
e.printStackTrace();
Log.e("erreurJSON", e.getMessage());
}
//I don't know how do this part Intent intent = newIntent(context, listMirorActivity.class);
startActivity(intent);
}
}, newResponse.ErrorListener() {
@OverridepublicvoidonErrorResponse(VolleyError error) {
Log.e("onErrorResponse", error.toString());
}
}){
@OverridepublicMap<String, String> getParams() throws AuthFailureError {
HashMap<String, String> params = newHashMap<String, String>();
params.put("grant_type", "password");
params.put("username", login);
params.put("password", password);
return params;
}
@OverridepublicMap<String, String> getHeaders() throws AuthFailureError {
Map<String,String> headers = newHashMap<String, String>();
// add headers <key,value>String credentials = ressources.client_id + ":" + ressources.client_secret;
String auth = "Basic "
+ Base64.encodeToString(credentials.getBytes(),
Base64.NO_WRAP);
headers.put("Authorization", auth);
return headers;
}
};
queue.add(stringRequest);
}
and in your activity change req.TokenRequest(login, password);
with req.TokenRequest(ConnexionActivity.this,login, password);
Post a Comment for "How Open A New Activity On A Onresponse Of Volley"