public static void get(Context context, String uString, BinaryHttpResponseHandler bHandler) //下载数据使用,会返回byte数据 { if (isNetworkConnected(context)) { client.cancelRequests(context, true); client.get(uString, bHandler); } else { makeText(context); } }
public static void post(Context context, String uString, BinaryHttpResponseHandler res) { if (isNetworkConnected(context)) { client.cancelRequests(context, true); client.post(uString, res); } else { makeText(context); } }
private void startLoad() { AsyncHttpClient client = new AsyncHttpClient(); client.get( "http://farm3.staticflickr.com/2004/2249945112_caa85476ef_o.jpg", new BinaryHttpResponseHandler() { @Override public void onSuccess(byte[] binaryData) { Log.d(TAG, "onSuccess"); Bitmap bitmap = BitmapFactory.decodeByteArray( binaryData, 0, binaryData.length); ImageView imageView = ((ImageView) findViewById(R.id.image)); imageView.setImageBitmap(bitmap); imageView.setVisibility(View.VISIBLE); findViewById(R.id.progress).setVisibility(View.GONE); } @Override public void onFailure(Throwable error, String content) { error.printStackTrace(); Log.d(TAG, "onFailure"); } }); RequestParams param = new RequestParams(); param.put("hpge", "fuga"); }
private void getTreeImage(String name, BinaryHttpResponseHandler handler) { JSONObject photo = this.getMostRecentPhoto(); if (photo != null) { String url = photo.optString(name); if (url != null) { RequestGenerator rg = new RequestGenerator(); rg.getImage(url, handler); } } }
public static void get(String uString, BinaryHttpResponseHandler bHandler) { client.get(uString, bHandler); }
public static void get(String urlString, RequestParams params, BinaryHttpResponseHandler bHandler) { client.get(urlString, params, bHandler); }
public void downloadAppCache() { AsyncHttpClient client = new AsyncHttpClient(); client.get(url, new BinaryHttpResponseHandler(new String[] { ".*" /*"application/x-7z-compressed"*/}) { @Override public void onSuccess(byte[] data) { // Successfully got a response Log.d(TAG,"URL Downloaded: " + url); _data = data; new Thread(new Runnable() { public void run() { try { RemoteAppCacheRandomAccessMemory istream = new RemoteAppCacheRandomAccessMemory(_data); extractAppCache(istream, outputPath); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).start(); } @Override public void onFinish() { // TODO Auto-generated method stub super.onFinish(); } @Override public void onStart() { // TODO Auto-generated method stub super.onStart(); } @Override public void onFailure(int statusCode, Header[] headers, byte[] binaryData, Throwable error) { // TODO Auto-generated method stub Log.d(TAG,"Failed to download: " + url); super.onFailure(statusCode, headers, binaryData, error); } }); }
@Override public void onReceive(final Context context, final Intent intent) { try { if (intent == null) { Log.d(TAG, "Receiver intent null"); } else { String action = intent.getAction(); if (action.equals(intentAction)) { JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data")); Iterator<String> itr = json.keys(); while (itr.hasNext()) { String key = (String) itr.next(); if (key.equals(ViewProfileActivity.USER_ID_KEY)) { final long userId = json.getLong(key); final boolean inResponse = json.getBoolean(responseKey); final int notificationId = (int)userId; final String username = json.getString(alertKey); String jsonChatMessage = null; if (json.has(messageKey)) { jsonChatMessage = json.getString(messageKey); } final String chatMessage = jsonChatMessage; final String message = chatMessage != null ? chatMessage : (username + (inResponse ? " has accepted your request." : " has requested to connect with you.")); final String skills = json.getString(skillsKey); final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle() .setBigContentTitle(username).bigText(message) .setSummaryText(skills); final AsyncHttpClient client = new AsyncHttpClient(); client.get(User.getProfileImageUrl(userId, 200), new BinaryHttpResponseHandler() { @Override public void onSuccess(byte[] fileData) { final Bitmap icon = UIUtils.decode(fileData); Intent pupInt = new Intent(context, chatMessage != null ? ChatActivity.class : ViewProfileActivity.class); pupInt.putExtra(ViewProfileActivity.USER_ID_KEY, userId); if (!inResponse && chatMessage == null) { DataService.addResponsePending(userId); } int requestID = (int) System.currentTimeMillis(); pupInt.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(context, requestID, pupInt, PendingIntent.FLAG_UPDATE_CURRENT); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(username) .setContentText(message) .setOnlyAlertOnce(true) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setAutoCancel(true) .setStyle(style) .setLargeIcon(icon) .setContentIntent(contentIntent); notificationManager.notify(notificationId, builder.build()); } }); } } } } } catch (JSONException e) { Log.d(TAG, "JSONException: " + e.getMessage()); } }
public static void get(String uString, BinaryHttpResponseHandler bHandler) //下载数据使用,会返回byte数据 { client.get(uString, bHandler); }
public void getTreePhoto(BinaryHttpResponseHandler handler) { getTreeImage(PHOTO_IMAGE, handler); }
public void getImage(String imageUrl, BinaryHttpResponseHandler binaryHttpResponseHandler) { client.getImage(imageUrl, binaryHttpResponseHandler); }
public void getImage(String imageUrl, BinaryHttpResponseHandler handler) { if (imageUrl.startsWith("/")) { imageUrl = safePathJoin(baseUrl, imageUrl); } client.get(imageUrl, handler); }
/** * Get the most recent tree thumbnail for this plot, by way of an * asynchronous response handler. * * @param handler image handler which will receive callback from async http * request */ public void getTreeThumbnail(BinaryHttpResponseHandler handler) { getTreeImage(PHOTO_THUMBNAIL, handler); }