2016-10-07 6 views
1
내가 setRequestMethod 같은 다양한 방법을 사용할

와의 setRequestProperty를 HttpURLConnection의를 사용할 수 있습니다어떻게, 글라이드

여기 내가 글라이드 라이브러리 대신 비동기 작업

를 사용하여 구현해야하는 코드의 조각이다 미리 감사드립니다.

public class ImageLoadingAsyncTask extends AsyncTask<Integer, Void, Void> { 
     Bitmap bmp; 

     @Override 
     protected void onPreExecute() { 
      super.onPreExecute(); 
      pb_imageProgressBar.setVisibility(VISIBLE); 
     } 

     @Override 
     protected Void doInBackground(Integer... integers) { 

      String url = PrefManager.getInstanceUrl() 
        + "clients/" 
        + integers[0] 
        + "/images?maxHeight=120&maxWidth=120"; 
      Log.d("ashu",url); 
      try { 
       HttpURLConnection httpURLConnection = (HttpURLConnection) (new URL(url)) 
         .openConnection(); 
       httpURLConnection.setRequestMethod("GET"); 
       httpURLConnection.setRequestProperty(MifosInterceptor.HEADER_TENANT, 
         "default"); 
       httpURLConnection.setRequestProperty(MifosInterceptor.HEADER_AUTH, 
         PrefManager.getToken()); 
       httpURLConnection.setRequestProperty("Accept", "application/octet-stream"); 
       httpURLConnection.setDoInput(true); 
       httpURLConnection.connect(); 
       InputStream inputStream = httpURLConnection.getInputStream(); 
       bmp = BitmapFactory.decodeStream(inputStream); 
       httpURLConnection.disconnect(); 
      } catch (MalformedURLException e) { 
      } catch (IOException ioe) { 
      } 
      return null; 
     } 


     @Override 
     protected void onPostExecute(Void aVoid) { 
      if (bmp != null) { 
       iv_clientImage.setImageBitmap(bmp); 
      } else { 
       iv_clientImage.setImageDrawable(
         ContextCompat.getDrawable(getActivity(), R.drawable.ic_launcher)); 
       pb_imageProgressBar.setVisibility(GONE); 
      } 

     } 
    } 
+0

글라이드를 사용하는 경우이 작업을 수행 할 필요가 없습니다. 내가 여기서 뭔가를 놓치고 있니? –

+0

@AshwaniK url 충분치 않아요 [link] (https://demo.openmf.org/fineract-provider/api/v1/clients/11/images?maxHeight=120&maxWidth=120) 우리가 문자열에서 얻는 링크를 확인하십시오 url –

답변

0

글라이드를 사용하는 경우 HttpUrlConnection이 필요하지 않습니다. 글라이드를 직접 호출하십시오.

String url = PrefManager.getInstanceUrl() 
        + "clients/" 
        + integers[0] 
        + "/images?maxHeight=120&maxWidth=120"; 

GlideUrl glideUrl = new GlideUrl(url, new LazyHeaders.Builder() 
       .addHeader((MifosInterceptor.HEADER_TENANT, "default") 
       .addHeader(MifosInterceptor.HEADER_AUTH, PrefManager.getToken()) 
       .addHeader("Accept", "application/octet-stream") 
       .build()); 
Glide.with(getActivity()).load(glideUrl).into(iv_clientImage); 
+0

안녕하세요 @ hakim URL url로 변환 : https://demo.openmf.org/fineract-provider/api/v1/clients/11/images?maxHeight=120&maxWidth=120 그리고 다음과 같은 오류 메시지가 나타납니다 : ** Whitelabel 오류 페이지 이 응용 프로그램에는/error에 대한 명시적인 매핑이 없으므로이를 대체로 볼 수 있습니다. 금요일 10 월 7 일 13:10:24 UTC 2016 예기치 않은 오류가 발생했습니다 (유형 = 잘못된 요청, 상태 = 400). 테넌트 식별자가 없습니다. 'Fineract-Platform-TenantId'의 요청 헤더를 추가하거나 요청 URL의 쿼리 문자열에 'tenantIdentifier'매개 변수를 추가하십시오. ** –

+0

@ TOP_GUN007 이미지 경로가 유효하지 않으므로 이미지 경로가 유효한지 확인하십시오. 웹 브라우저에서 경로를 열어 테스트 할 수 있습니다. – hakim

+0

(log.d)을 사용하는 URL이 있으며 올바른 인증을 –

관련 문제