반응형
블로그 이미지
sense.45

공지사항

최근에 올라온 글

최근에 달린 댓글

글 보관함

calendar

1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28

안드로이드 WIFI 연결 체크

2019. 2. 12. 11:21 | Posted by sense.45
반응형

WIFI 연결 체크




private boolean checkWifiOnAndConnected() {
    WifiManager wifiMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    if (wifiMgr.isWifiEnabled()) { // Wi-Fi adapter is ON

        WifiInfo wifiInfo = wifiMgr.getConnectionInfo();

        if( wifiInfo.getNetworkId() == -1 ){
            return false; // Not connected to an access point
        }
        return true; // Connected to an access point
    }
    else {
        return false; // Wi-Fi adapter is OFF
    }
}


<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

출처 : https://stackoverflow.com/questions/3841317/how-do-i-see-if-wi-fi-is-connected-on-android





public static String getNetworkType(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    return info.getTypeName();
}


아래 함수는 약간만 손보면 사용하기 좋겠슴다.

public static boolean isInternetIsConnected(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    if (activeNetwork != null) { // connected to the internet
        if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
            // connected to wifi
            return true;

        } else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
            // connected to the mobile provider's data plan
            return true;
        }
    } else {
        // not connected to the internet
        return false;
    }
    return false;
}


출처 : https://stackoverflow.com/questions/48077755/how-to-check-programmatically-that-wifi-is-connected-or-data-pack-is-enabled-but


반응형

'Android' 카테고리의 다른 글

안드로이드 Calendar.getInstance API level24  (0) 2018.07.10
NFC NTAG 213  (1) 2018.03.26
How to Change the Text Color of a Substring  (0) 2018.03.20

안드로이드 Calendar.getInstance API level24

2018. 7. 10. 10:47 | Posted by sense.45
반응형

안드로이드 개발시 Calendar.getInstance를 사용할 일이 자주 있습니다.


뜬금없이 오류가 발생합니다.



처음에는 API level을 24로 바꿔서 실행했습니다.


잘 실행됩니다.


근데 너무 최신버전입니다.

(안드로이드 플랫폼 버전7입니다.)


다시 여기 저기 찿아보니 


import를 잘못 한거랍니다.


import할때 Alt+ Enter하면

아래와 같이 나오면 java.util.Calendar를 선택합니다..





아래 와 같이 변경하면 됩니다.



이제 api level을 20이하로도 가능하게 되었습니다.


반응형

'Android' 카테고리의 다른 글

안드로이드 WIFI 연결 체크  (0) 2019.02.12
NFC NTAG 213  (1) 2018.03.26
How to Change the Text Color of a Substring  (0) 2018.03.20

NFC NTAG 213

2018. 3. 26. 14:36 | Posted by sense.45
반응형

NFC NTAG 213 


Near Field Communication는 말 그대로 근거리 통신입니다.


안드로이드로 뭔가 할게 있나 보니 nfc가 많이 쓰이고 있습니다.


그러던 중 알리익스프레스에서 10개에 1.22달러하는 녀석이 보입니다.



당장 뭔가 할 것도 아니지만 배송료가 없는 조건이라 질러 봤습니다.


국내에서 구매하면 장당 4~500원합니다.

배송료는 2500원이고요ㅠㅠ


지난 17일 주문했다가 오늘 배송조회 하니 Depart from transit country상태입니다.




아마 다음주 안에는 받아 볼 수 있을 것 같습니다. 


2500원 아낄려다 사리가 꽤 많이 쌓이고 있습니다.


물론 받고 바로 nfc개발 할 것도 아니라 급할 것도 없습니다.


개발이 완료되면 테스트 결과를 알려 드리겠습니다.



반응형

'Android' 카테고리의 다른 글

안드로이드 WIFI 연결 체크  (0) 2019.02.12
안드로이드 Calendar.getInstance API level24  (0) 2018.07.10
How to Change the Text Color of a Substring  (0) 2018.03.20

How to Change the Text Color of a Substring

2018. 3. 20. 14:06 | Posted by sense.45
반응형

TextView textView = findViewById(R.id.text_view);


String text = 'I want THIS and THIS to be colored";


//SpannableString ss =  new SpannableString(text);

SpannableStringBuilder ssb = new SpannableStringBuilder(text);


ForegroundColorSpan fcsRed = new ForegroundColorSpan(Color.RED);

ForegroundColorSpan fcsGreen = new ForegroundColorSpan(Color.Green);

BackgroundColorSpan bcsYellow = new BackgroundColorSpan (Color.Green);


ssb.setSpan(fcsRed, 7,11, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

ssb.setSpan(fcsGreen, 16,20, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

ssb.setSpan(fcsYellow, 27,34, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);


ssb.append(" and this to be appended");


textView.setText(ssb);





원본:https://www.youtube.com/watch?v=tTLmz-JKxsI



반응형

'Android' 카테고리의 다른 글

안드로이드 WIFI 연결 체크  (0) 2019.02.12
안드로이드 Calendar.getInstance API level24  (0) 2018.07.10
NFC NTAG 213  (1) 2018.03.26
이전 1 다음