'android webfile 존재 유무 확인'에 해당되는 글 1건

728x90

회원 로그인 후 회원 정보를 가져와서 ProfileView 함수에 처리하는 로직이다.


private void ProfileView() {
    ImageView img_profile = findViewById(R.id.img_profile);
    TextView userNM = findViewById(R.id.tv_userNM);
    TextView mobileNO = findViewById(R.id.tv_mobileNO);

    String photoURL = Value.PhotoADDRESS + PrefsHelper.read("profileImg","") + ".jpg";
    // 사진 이미지가 존재하지 않을 수도 있으므로 존재 여부를 체크하여 존재하면 ImageView 에 표시한다.
    PhotoURLExists task = new PhotoURLExists();
    try {
        if(task.execute(photoURL).get()==true){
            Glide.with(mContext).load(photoURL).override(170, 200).into(img_profile);
        }
    } catch (ExecutionException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    userNM.setText(PrefsHelper.read("userNM",""));
    mobileNO.setText(PrefsHelper.read("mobileNO",""));
}

private class PhotoURLExists extends AsyncTask<String, Void, Boolean> {
    @Override
    protected Boolean doInBackground(String... params) {
        try {
            HttpURLConnection.setFollowRedirects(false);
            HttpURLConnection con =  (HttpURLConnection) new URL(params[0]).openConnection();
            con.setRequestMethod("HEAD");
            return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
} 


앱 build.gradle 추가

implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' 


Glide.with(this)
    .load("이미지 url...")
    .override(이미지 사이즈) // ex) override(170, 200)
    .into(imageView);


Glide 최신버전 확인 : https://github.com/bumptech/glide


참고하면 도움되는 자료

AsyncTask return 결과 처리하는 방법 : https://link2me.tistory.com/1516

[Java] SharedPreferences Singleton

출처: https://link2me.tistory.com/1827 [소소한 일상 및 업무TIP 다루기]
[Java] SharedPreferences Singleton

출처: https://link2me.tistory.com/1827 [소소한 일상 및 업무TIP 다루기]
[Java] SharedPreferences Singleton

출처: https://link2me.tistory.com/1827 [소소한 일상 및 업무TIP 다루기]

[Java] SharedPreferences Singletonhttps://link2me.tistory.com/1827


블로그 이미지

Link2Me

,