Skip to content

Instantly share code, notes, and snippets.

public abstract class LoginableActivity extends Activity {
private static final int LOGIN = 42;
public static boolean loggedIn = false;
public void login(View target) {
startActivityForResult(new Intent(this, LoginActivity.class), LOGIN);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
@smaspe
smaspe / GetFile.java
Created June 10, 2013 09:37
File download 1-liner
new DefaultHttpClient().execute(new HttpGet("http://www.example.com/somefile.ext"))
.getEntity().writeTo(
new FileOutputStream(new File(root,"Video.mp4")));
public class TweetsRequest extends JsonObjectRequest {
public TweetsRequest(String url, Listener<JSONObject> listener,
ErrorListener errorListener, List<NameValuePair> params) {
super(url + "?" + URLEncodedUtils.format(params, "UTF-8"),
null, listener, errorListener);
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
final class TokenRequest extends StringRequest {
TokenRequest(int method, String url, Listener<String> listener,
ErrorListener errorListener) {
super(method, url, listener, errorListener);
}
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("grant_type", "client_credentials");