Created
April 13, 2016 16:30
-
-
Save ardeay/7fca0db056c2837933331c75def5c3be to your computer and use it in GitHub Desktop.
Example of using the EchoMTGAPI Wrapper Singleton with a call back in an activity or fragment class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// auth example, would be inside an activity or fragment class method | |
SharedPreferences sharedPref; | |
sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); | |
String email = "your@email.com"; | |
String pass = "asdfsbfsbsadfsa"; | |
EchoMTGJavaAPIWrapper.getInstance(getActivity().getApplicationContext()).authRequest(new EchoMTGJavaAPIWrapper.EchoCallback(){ | |
@Override | |
public void onSuccess(String result){ | |
JSONObject jsonObject= null; | |
String token = null; | |
try { | |
jsonObject = new JSONObject(result); | |
token = jsonObject.getString("token"); | |
} catch (JSONException e) { | |
e.printStackTrace(); | |
} | |
Toast.makeText(getActivity().getApplicationContext(), "Successful Login", Toast.LENGTH_SHORT).show(); | |
SharedPreferences.Editor editor = sharedPref.edit(); | |
editor.putString(getString(R.string.token_reference), token); | |
editor.commit(); | |
} | |
},email,pass); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment