is Bluetooth Network Connection By Type - Android Bluetooth

Android examples for Bluetooth:Bluetooth State

Description

is Bluetooth Network Connection By Type

Demo Code


//package com.java2s;
import android.annotation.TargetApi;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import android.os.Build;

public class Main {

    public static final int NETWORK_TYPE_NO_CONNECTION = -1231545315;

    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
    public static boolean isBluetoothByType(Context context) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
            return false;
        } else {//from w w  w  .  j a  va  2s.c o m
            return getCurrentNetworkType(context) == ConnectivityManager.TYPE_BLUETOOTH;
        }
    }

    public static int getCurrentNetworkType(Context context) {
        NetworkInfo networkInfo = ((ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE))
                .getActiveNetworkInfo();
        return networkInfo != null ? networkInfo.getType()
                : NETWORK_TYPE_NO_CONNECTION;
    }
}

Related Tutorials