티스토리 뷰

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.net.ConnectivityManager;

import android.net.NetworkInfo;

import android.widget.Toast;

 

public class ConnReceiver extends BroadcastReceiver {

 

    @Override

    public void onReceive(Context context, Intent intent) {

        String action = intent.getAction();

         

        // 네트워크 상태가 변경되었을때 호출되는 메소드.

        if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {

            ConnectivityManager connectivityManager =

                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

            NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();

            NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

            Toast.makeText(context,"Active Network Type : " + activeNetInfo.getTypeName() , Toast.LENGTH_SHORT).show();

            Toast.makeText(context,"Mobile Network Type : " + mobNetInfo.getTypeName() , Toast.LENGTH_SHORT).show();

        }

    }

}



출처 : http://mainia.tistory.com/549 

댓글
댓글쓰기 폼
공지사항
Total
742,057
Today
46
Yesterday
86
«   2019/08   »
        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 29 30 31
글 보관함