ȸ¿ø°¡ÀԡžÆÀ̵ð/ºñ¹øã±â
ȨÀ¸·Î


À¥¿¡¼­ ÆÄÀÏ »çÀÌÁî¿Í ÄÜÅÙÆ®(ÄÁÅÙÃ÷) ŸÀÔ ¾Ë¾Æº¸´Â »ùÇÃÄÚµå
7³â Àü
À¥¿¡¼­ ÆÄÀÏ »çÀÌÁî¿Í ÄÜÅÙÆ®(ÄÁÅÙÃ÷) ŸÀÔ ¾Ë¾Æº¸´Â »ùÇÃÄÚµå
Sample Code for checking file size and content type.


private long fileSize = 0;
private String contentType = "";
private void checkFileSizeAndType(final String openUrl){
    
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            URL mUrl;
            try {
                mUrl = new URL(openUrl);
                final URLConnection connection = mUrl.openConnection();
                connection.setConnectTimeout(8000);
                connection.setReadTimeout(8000);
                connection.connect();
                String content_length = connection.getHeaderField("Content-Length");
                contentType = connection.getHeaderField("Content-Type");
                if(content_length == null){
                    fileSize = -1;
                }else{
                    fileSize = Long.parseLong(content_length);
                }
            } catch (SSLException e) {
                fileSize = -2;
            } catch (NullPointerException e) {
                fileSize = -1;
                e.printStackTrace();
            } catch (MalformedURLException e) {
                fileSize = -1;
                e.printStackTrace();
            } catch (IOException e) {
                fileSize = -1;
                e.printStackTrace();
            }

            if(fileSize == -2){
                TrustManager[] trustAllCerts = new TrustManager[]{ new X509TrustManager() {
                            public X509Certificate[] getAcceptedIssuers() {return null;}
                            public void checkClientTrusted(X509Certificate[] certs, String authType) {}
                            public void checkServerTrusted(X509Certificate[] certs, String authType) {}
                        }
                };
                try {
                    SSLContext sc = SSLContext.getInstance("SSL");
                    sc.init(null, trustAllCerts, new SecureRandom());
                    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
                } catch (Exception e) {
                }
                try {
                    mUrl = new URL(openUrl);
                    final URLConnection connection = mUrl.openConnection();
                    connection.setConnectTimeout(8000);
                    connection.setReadTimeout(8000);
                    connection.connect();
                    String content_length = connection.getHeaderField("Content-Length");
                    if(content_length == null){
                        fileSize = -1;
                    }else{
                        fileSize = Long.parseLong(content_length);
                    }
                } catch (NullPointerException e) {
                    fileSize = -1;
                    e.printStackTrace();
                } catch (MalformedURLException e) {
                    fileSize = -1;
                    e.printStackTrace();
                } catch (IOException e) {
                    fileSize = -1;
                    e.printStackTrace();
                }
            }//SSL
            
            APLog.d(TAG, CLASS, "fileSize " + fileSize + " /contentType " + contentType);
            getMainHandler().post(new APRunnable() {
                @Override
                protected void runs() {
                    if(fileSize > 0 && isVideoContentType(contentType)) {
                        afterFileSizeAndType(true);
                    }
                    else {
                        afterFileSizeAndType(false);
                    }
                }
            });
        }
    });
    thread.setDaemon(true);
    thread.start();
}

private boolean isVideoContentType(String type) {
    if(type.contains("/")) {
        
        if(type.equalsIgnoreCase("application/x-mpegURL")
            || type.equalsIgnoreCase("application/vnd.apple.mpegurl")) return true;
        String[] t = type.split("/");
        if(t.length > 1) {
            if(t[0].equalsIgnoreCase("video")) {
                return true;
            }
        }
    }
    return false;
}

ÃßõÃßõ : 255 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
127
[Android] Intent È°¿ë ¿¹½Ã
126
Android ¼³Ä¡µÈ ¾îÇà ¸ñ·Ï PackageInfo¸¦ ÅëÇØ °¡Á®¿À±â ¹× ´Ù¸¥ ¾îÇà ½ÇÇà
125
[ANDROID(¾Èµå·ÎÀ̵å) ¾Û °³¹ß ±âÃÊ] MEDIAPLAYER À½¾Ç Àç»ýÇϱâ
124
[¾Èµå·ÎÀ̵å] ¿ÜºÎ ¾Û ½ÇÇà
123
¾Èµå·ÎÀÌµå ¼º´ÉÀ» À§ÇÑ ¼³°è
122
ÆÄÀÏ ¾÷·Îµå ¹× ÆĶó¸ÞÅÍ Àü¼Û (sending file & parameters by MultipartEntity / post)
121
MediaPlayer °¡·ÎÀÏ ¶§ UI ¼û±â°í Ç®½ºÅ©¸° ¸¸µé±â
120
À¥ºä¿¡¼­ html ÅÂ±× ¾ø¾Ö´Â ¹ý(Remove the html tag on loading web page in WebView)
119
´Ù¸¥ ¾Û ½ÇÇàÇϰųª Ç÷¹ÀÌ ½ºÅä¾î·Î À̵¿(Launch another app by code)
118
À¥ ºä¿¡¼­ ÅÂ±× Á¤º¸ ÃàÃâÇϱâ(Get the information of html tag in WebView of android)
117
ÀÚµ¿À¸·Î ¿¡µðÆ®ºä¿¡ Æ÷Ä¿½º µÇ´Â °Í ¸·±â
116
addJavascriptInterface ¿À·ù(Android WebView.addJavascriptInterface not Working)
115
Ä¿½ºÅÒ Å佺Ʈ ¶ç¿ì±â(To show Custom Toast)
À¥¿¡¼­ ÆÄÀÏ »çÀÌÁî¿Í ÄÜÅÙÆ®(ÄÁÅÙÃ÷) ŸÀÔ ¾Ë¾Æº¸´Â »ùÇÃÄÚµå
113
¾Èµå·ÎÀ̵å ÅؽºÆ® ºä¿¡¼­ Áö¿øÇÏ´Â HTML ű׵é
112
ÀÎÅÍ³Ý ÁÖ¼Ò À¯È¿¼º °Ë»ç (regular expression for url)
111
SpannableStringÀ¸·Î ÅؽºÆ® ºä¿¡ ¾ÆÀÌÄÜ ³Ö´Â ¹ý
110
½ÇÇà°¡´ÉÇÑ ¾Û ¸ñ·Ï (Get launchable apps in android)
109
HTMLÀ» ¾Èµå·ÎÀ̵å À¥ºä¿¡ ¸ðµÎ º¸ÀÌ°Ô Çϱâ Using WebView ViewPort in android
108
so ÆÄÀÏ ¾Èµå·ÎÀÌµå ½ºÆ©µð¿À¿¡¼­ »ç¿ëÇÏ´Â ¹ý
107
[¾Èµå·ÎÀ̵å] È­¸é »çÀÌÁî ±¸Çϱâ
106
[¾Èµå·ÎÀ̵å] ¾Èµå·ÎÀÌµå ½ºÆ©µð¿À¿¡¼­ ºôµå ÆÄÀÏ À̸§ ¼öÁ¤Çϱâ.
105
¿ÜºÎ ¾Û ½ÇÇà½ÃÅ°±â (launch external app in android)
104
Service & Notification(¾Ë¸²¹Ù¶ç¿ì±â) ÀÌ¿ëÇϱâ
103
È­¸é ȸÀü(rotation) ó¸®
102
[Android] Àüüȭ¸é, title bar ¾ø¾Ö±â, status bar ¾ø¾Ö±â
101
ANDROID(¾Èµå·ÎÀ̵å) ¾Û °³¹ß ±âÃÊ] MEDIAPLAYER À½¾Ç Àç»ýÇϱâ
100
[Android]MediaPlayer¿¡¼­ »ç¿îµå¸¦ Àç»ýÇÏ´Â µÎ °¡Áö °æ·Î
99
¾Èµå·ÎÀ̵å Intent »ç¿ë¹ý
98
¾Èµå·ÎÀ̵å È­¸é Á¤¸®
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.