-1

In my application it is require the status of Bluetooth and location, so that the functionality always depends on those status . is there any way to get the enable or disable status of both Bluetooth and location at same time?. any way i got the status , but how would get automatically notified inside my fragment. so that i will do some refresh kind of work.

Thanks in advance.

2 Answers2

0

Have a look at LocationManager and BluetoothManager. Basic understanding of these classes will let you get you answer. There are plenty of answers already floating in this forum too.

Saurav
  • 560
  • 4
  • 17
0

To check if Location Services are enabled:

/**
     * Method to check if location enable
     */
public static boolean isLocationEnabled(Context p_context) {
    int m_locationMode = 0;
    String m_locationProviders;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
        try {
            m_locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);

        } catch (SettingNotFoundException m_e) {
            m_e.printStackTrace();
        }

        return m_locationMode != Settings.Secure.LOCATION_MODE_OFF;

    }else{
        m_locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
        return !TextUtils.isEmpty(m_locationProviders);
    }


}

permission in menifest:

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

To check Bluetooth enable:

/**
         * Method to check if bluetooth enable
         */
public boolean isBluetoothEnabled()
    {
        BluetoothAdapter m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        return m_BluetoothAdapter.isEnabled();

    }

permission in menifest:

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