1) AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
2) 샘플소스
public void getDetailItem(String sn) {
Call<ResponseBody> call = app.retrofitAPI.getDetailItem(sn);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
try {
if (response.code() == 200) {
String json = response.body().string();
List<ShoppingDetail> list = Arrays.asList(new ObjectMapper().readValue(json, ShoppingDetail[].class));
editText8.setText(list.get(0).getItm_nm());
editText9.setText(list.get(0).getItm_qy());
editText10.setText(list.get(0).getItm_unit());
editText11.setText(list.get(0).getItm_pc());
editText12.setText(list.get(0).getReffer_matter());
String link = replaceFileName(call.request().url() + list.get(0).getFile_cours());
Thread thread = new Thread() {
@Override
public void run() {
try {
URL url = new URL(getString(R.string.baseUrl) + link);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
} catch (Exception e) {
e.printStackTrace();
}
}
};
thread.start();
try {
thread.join();
imageView1.setImageBitmap(bitmap);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Log.e("Retrofit Call :: ", "onFailure : getDetailItem");
}
});
}
감사합니다.
출처 : inma.tistory.com/64
'Tip' 카테고리의 다른 글
[전자정부] ant-style 권한 url (0) | 2021.02.23 |
---|---|
[mariadb] auto_increment를 활룡한 primary key 구성방법 (0) | 2021.02.23 |
[안드로이드] 사진 업로드할 때 사용하는 jsp 페이지 (0) | 2021.02.22 |
gitlab project 설정 (0) | 2021.02.22 |
[안드로이드] 임시 저장소 sharedPreference (0) | 2021.02.22 |