@Override protected Void doInBackground(Void... params) { String url = Constants.URL_REGISTER_PUSH + _id + "&provider=ANDROID"; HttpEntity httpEntity = null; HttpClient client = new DefaultHttpClient(); ServiceHandler sh = new ServiceHandler(); try { client.getConnectionManager().getSchemeRegistry().register(sh.getMockedScheme()); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } HttpGet method = new HttpGet(url); method.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); method.setHeader("Authorization", token.getToken_type() + " " + token.getAccess_token()); try { HttpResponse response = client.execute(method); httpEntity = response.getEntity(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
public String uploadService(ArrayList<String> arrlink, TokenDTO token, String description) { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost(Constants.URL_UPLOAD); postRequest.setHeader("Authorization", token.getToken_type() + " " + token.getAccess_token()); HttpEntity httpEntity = null; try { MultipartEntity reqEntity = new MultipartEntity(); reqEntity.addPart("Desc", new StringBody(description)); reqEntity.addPart("CountryCode", new StringBody("1")); for (String pathImg : arrlink) { reqEntity.addPart("filename", new FileBody(new File(pathImg))); } postRequest.setEntity(reqEntity); HttpResponse response = httpclient.execute(postRequest); httpEntity = response.getEntity(); responsecontent = EntityUtils.toString(httpEntity); } catch (Exception e) { // TODO: handle exception } return responsecontent; }
@SuppressLint("SimpleDateFormat") @Override public void onClick(View v) { Intent intent; switch (v.getId()) { case R.id.img_view_push_messages: if (InternetUtils.getInstance().isConnectingToInternet(HomeActivity.this)) { intent = new Intent(HomeActivity.this, ViewMessageActivity.class); startActivity(intent); } else { Toast.makeText(HomeActivity.this, "no net work", Toast.LENGTH_LONG).show(); } break; case R.id.img_new_push_message: intent = new Intent(HomeActivity.this, UpdateAnimalActivity.class); startActivity(intent); break; case R.id.contact_us: intent = new Intent(HomeActivity.this, ContactUsActivity.class); startActivity(intent); break; case R.id.update: TokenModel tokenModel = TokenModel.getInstance(); TokenDTO tokenDTO = tokenModel.getToken(HomeActivity.this); String dateExpires = tokenDTO.getExpires(); Date date2 = null; Date date1 = null; String pattern = "EEE, dd MMM yyyy HH:mm:ss Z"; SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.ENGLISH); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String currentDay = sdf.format(new Date()); String currentDayExpires = format.format(new Date()); try { date1 = format.parse(currentDayExpires); date2 = format.parse(dateExpires); if (date1.compareTo(date2) < 0) { if (InternetUtils.getInstance().isConnectingToInternet(this)) { this.runOnUiThread( new Runnable() { @Override public void run() { String path = Constants.URL_CATEGORY; String[] strs = path.split("/"); File file = new File( Environment.getExternalStorageDirectory() + "/" + Constants.APP_NAME + "/" + strs[4] + "/"); // deleteDirectory(file); DeleteRecursive(file); adapter.notifyDataSetChanged(); grid.invalidateViews(); } }); new AsystaskUpdateAnimal(currentDay, tokenDTO, HomeActivity.this).execute(); flag = true; // arrData = new ArrayList<Object>(); // InitData(); // adapter = new AnimalCategoryMasterAdapter(this, // R.layout.grid_row, // arrData); adapter.notifyDataSetChanged(); } else { Toast.makeText(HomeActivity.this, "no network", Toast.LENGTH_LONG).show(); } } } catch (Exception e) { // TODO: handle exception } break; default: break; } }