Example usage for android.bluetooth BluetoothAdapter getDefaultAdapter

List of usage examples for android.bluetooth BluetoothAdapter getDefaultAdapter

Introduction

In this page you can find the example usage for android.bluetooth BluetoothAdapter getDefaultAdapter.

Prototype

public static synchronized BluetoothAdapter getDefaultAdapter() 

Source Link

Document

Get a handle to the default local Bluetooth adapter.

Usage

From source file:com.authorwjf.bounce.BluetoothChatService.java

/**
 * Constructor. Prepares a new BluetoothChat session.
 * @param context  The UI Activity Context
 * @param handler  A Handler to send messages back to the UI Activity
 *///ww w  . j  av a2s. c  o  m
public BluetoothChatService(Context context, Handler handler) {
    mAdapter = BluetoothAdapter.getDefaultAdapter();
    mState = STATE_NONE;
    mHandler = handler;
    mapValues = new ConcurrentHashMap<String, String>();
}

From source file:org.apache.cordova.plugin.BluetoothPlugin.java

/**
 * Constructor for Bluetooth plugin//w  w  w  .ja  va 2 s . c om
 */
public BluetoothPlugin() {

    m_bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    m_bpBroadcastReceiver = new BPBroadcastReceiver();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
        try {
            Field actionUUID = BluetoothDevice.class.getDeclaredField("ACTION_UUID");
            BluetoothPlugin.ACTION_UUID = (String) actionUUID.get(null);
            Log.d("BluetoothPlugin", "actionUUID: " + actionUUID.getName() + " / " + actionUUID.get(null));
            Field extraUUID = BluetoothDevice.class.getDeclaredField("EXTRA_UUID");
            BluetoothPlugin.EXTRA_UUID = (String) extraUUID.get(null);
            Log.d("BluetoothPlugin", "extraUUID: " + extraUUID.getName() + " / " + extraUUID.get(null));
        } catch (Exception e) {
            logErr(e.getMessage());
        }
    }
}

From source file:org.apache.cordova.plugin.BluetoothPlugin2.java

/**
 * Constructor for Bluetooth plugin/*from w  w w .j  a  va  2s.  com*/
 */
public BluetoothPlugin2() {

    m_bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    m_bpBroadcastReceiver = new BPBroadcastReceiver();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
        try {
            Field actionUUID = BluetoothDevice.class.getDeclaredField("ACTION_UUID");
            BluetoothPlugin2.ACTION_UUID = (String) actionUUID.get(null);
            Log.d("BluetoothPlugin2", "actionUUID: " + actionUUID.getName() + " / " + actionUUID.get(null));
            Field extraUUID = BluetoothDevice.class.getDeclaredField("EXTRA_UUID");
            BluetoothPlugin2.EXTRA_UUID = (String) extraUUID.get(null);
            Log.d("BluetoothPlugin2", "extraUUID: " + extraUUID.getName() + " / " + extraUUID.get(null));
        } catch (Exception e) {
            logErr(e.getMessage());
        }
    }
}

From source file:org.lastmilehealth.collect.android.tasks.BluetoothService.java

/**
 * Constructor. Prepares a new BluetoothChat session.
 * @param handler A Handler to send messages back to the UI Activity
 *//*  w w  w. j ava2s.  c o  m*/
public BluetoothService(Handler handler, Context context) {
    mContext = context;
    mAdapter = BluetoothAdapter.getDefaultAdapter();
    mHandler = handler;
    mState = STATE_NONE;
}

From source file:jp.co.kayo.ykmjuku.andylib.DeviceListActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Bundle args = getArguments();//w ww  . ja v  a  2s . co m
    if (args != null) {
        mTag = args.getString("tag");
        mSecure = args.getBoolean("secure");
    }
    getDialog().setTitle(getString(R.string.select_device));

    // Setup the window
    View root = inflater.inflate(R.layout.device_list, container, false);

    // Initialize the button to perform device discovery
    Button scanButton = (Button) root.findViewById(R.id.button_scan);
    scanButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            doDiscovery();
            v.setVisibility(View.GONE);
        }
    });

    // Initialize array adapters. One for already paired devices and
    // one for newly discovered devices
    mPairedDevicesArrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.device_name);
    mNewDevicesArrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.device_name);

    // Find and set up the ListView for paired devices
    ListView pairedListView = (ListView) root.findViewById(R.id.paired_devices);
    pairedListView.setAdapter(mPairedDevicesArrayAdapter);
    pairedListView.setOnItemClickListener(mDeviceClickListener);

    // Find and set up the ListView for newly discovered devices
    ListView newDevicesListView = (ListView) root.findViewById(R.id.new_devices);
    newDevicesListView.setAdapter(mNewDevicesArrayAdapter);
    newDevicesListView.setOnItemClickListener(mDeviceClickListener);

    // Register for broadcasts when a device is discovered
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    getActivity().registerReceiver(mReceiver, filter);

    // Register for broadcasts when discovery has finished
    filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    getActivity().registerReceiver(mReceiver, filter);

    // Get the local Bluetooth adapter
    mBtAdapter = BluetoothAdapter.getDefaultAdapter();

    // Get a set of currently paired devices
    Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices();

    // If there are paired devices, add each one to the ArrayAdapter
    if (pairedDevices.size() > 0) {
        root.findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE);
        for (BluetoothDevice device : pairedDevices) {
            mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
        }
    } else {
        String noDevices = getResources().getText(R.string.none_paired).toString();
        mPairedDevicesArrayAdapter.add(noDevices);
    }

    return root;
}

From source file:com.example.mynsocial.BluetoothChat.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (D)// w  w w .  ja  v  a  2  s .  c  o m
        Log.e(TAG, "+++ ON CREATE +++");

    // Set up the window layout
    setContentView(R.layout.activity_fight);
    TextView text_touch = (TextView) findViewById(R.id.texttouch);

    title = (TextView) findViewById(R.id.titletext);

    // Get local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    // If the adapter is null, then Bluetooth is not supported
    if (mBluetoothAdapter == null) {
        Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        finish();
        return;
    }

    SharedPreferences sp = this.getSharedPreferences("loginPrefs", MODE_PRIVATE);
    fb_id = sp.getString("fb_id", fb_id);
    inputText = mBluetoothAdapter.getAddress();//??MAC
    NdefMessage message = create_RTD_TEXT_NdefMessage(inputText);
    mNfcAdapter.setNdefPushMessage(message, this);

}

From source file:org.debian.paulliu.kajiradoubra.controller.KajiraDouBraController.java

@Override
public void onStart() {
    super.onStart();
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBluetoothAdapter == null) {
        // Device does not support Bluetooth
        Log.w(LOGTAG, "No Bluetooth Adapter");
        return;//from w ww  . j a v  a 2 s .c o m
    }
    if (!mBluetoothAdapter.isEnabled()) {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
    }
}

From source file:org.lsc.hellocordova.BluetoothPlugin.java

@Override
public PluginResult execute(String action, JSONArray arg1, String callbackId) {
    Log.d("BluetoothPlugin", "Plugin Called");
    PluginResult result = null;/*from w w  w  . j  a  v  a 2 s  . c o  m*/
    context = (Context) this.ctx;

    // Register for broadcasts when a device is discovered
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    context.registerReceiver(mReceiver, filter);

    // Register for broadcasts when discovery starts
    filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
    context.registerReceiver(mReceiver, filter);

    // Register for broadcasts when discovery has finished
    filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    context.registerReceiver(mReceiver, filter);

    // Register for broadcasts when connectivity state changes
    filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    context.registerReceiver(mReceiver, filter);

    Looper.prepare();
    btadapter = BluetoothAdapter.getDefaultAdapter();
    found_devices = new ArrayList<BluetoothDevice>();

    if (ACTION_DISCOVER_DEVICES.equals(action)) {
        try {

            Log.d("BluetoothPlugin", "We're in " + ACTION_DISCOVER_DEVICES);

            found_devices.clear();
            discovering = true;

            if (btadapter.isDiscovering()) {
                btadapter.cancelDiscovery();
            }

            Log.i("BluetoothPlugin", "Discovering devices...");
            btadapter.startDiscovery();

            while (discovering) {
            }

            String devicesFound = null;
            int count = 0;
            devicesFound = "[";
            for (BluetoothDevice device : found_devices) {
                Log.i("BluetoothPlugin",
                        device.getName() + " " + device.getAddress() + " " + device.getBondState());
                if ((device.getName() != null) && (device.getBluetoothClass() != null)) {
                    devicesFound = devicesFound + " { \"name\" : \"" + device.getName() + "\" ,"
                            + "\"address\" : \"" + device.getAddress() + "\" ," + "\"class\" : \""
                            + device.getBluetoothClass().getDeviceClass() + "\" }";
                    if (count < found_devices.size() - 1)
                        devicesFound = devicesFound + ",";
                } else
                    Log.i("BluetoothPlugin",
                            device.getName() + " Problems retrieving attributes. Device not added ");
                count++;
            }

            devicesFound = devicesFound + "] ";

            Log.d("BluetoothPlugin - " + ACTION_DISCOVER_DEVICES, "Returning: " + devicesFound);
            result = new PluginResult(Status.OK, devicesFound);
        } catch (Exception Ex) {
            Log.d("BluetoothPlugin - " + ACTION_DISCOVER_DEVICES, "Got Exception " + Ex.getMessage());
            result = new PluginResult(Status.ERROR);
        }

    } else if (ACTION_IS_BT_ENABLED.equals(action)) {
        try {
            Log.d("BluetoothPlugin", "We're in " + ACTION_IS_BT_ENABLED);

            boolean isEnabled = btadapter.isEnabled();

            Log.d("BluetoothPlugin - " + ACTION_IS_BT_ENABLED,
                    "Returning " + "is Bluetooth Enabled? " + isEnabled);
            result = new PluginResult(Status.OK, isEnabled);
        } catch (Exception Ex) {
            Log.d("BluetoothPlugin - " + ACTION_IS_BT_ENABLED, "Got Exception " + Ex.getMessage());
            result = new PluginResult(Status.ERROR);
        }

    } else if (ACTION_ENABLE_BT.equals(action)) {
        try {
            Log.d("BluetoothPlugin", "We're in " + ACTION_ENABLE_BT);

            boolean enabled = false;

            Log.d("BluetoothPlugin", "Enabling Bluetooth...");

            if (btadapter.isEnabled()) {
                enabled = true;
            } else {
                enabled = btadapter.enable();
            }

            Log.d("BluetoothPlugin - " + ACTION_ENABLE_BT, "Returning " + "Result: " + enabled);
            result = new PluginResult(Status.OK, enabled);
        } catch (Exception Ex) {
            Log.d("BluetoothPlugin - " + ACTION_ENABLE_BT, "Got Exception " + Ex.getMessage());
            result = new PluginResult(Status.ERROR);
        }

    } else if (ACTION_DISABLE_BT.equals(action)) {
        try {
            Log.d("BluetoothPlugin", "We're in " + ACTION_DISABLE_BT);

            boolean disabled = false;

            Log.d("BluetoothPlugin", "Disabling Bluetooth...");

            if (btadapter.isEnabled()) {
                disabled = btadapter.disable();
            } else {
                disabled = true;
            }

            Log.d("BluetoothPlugin - " + ACTION_DISABLE_BT, "Returning " + "Result: " + disabled);
            result = new PluginResult(Status.OK, disabled);
        } catch (Exception Ex) {
            Log.d("BluetoothPlugin - " + ACTION_DISABLE_BT, "Got Exception " + Ex.getMessage());
            result = new PluginResult(Status.ERROR);
        }

    } else if (ACTION_PAIR_BT.equals(action)) {
        try {
            Log.d("BluetoothPlugin", "We're in " + ACTION_PAIR_BT);

            String addressDevice = arg1.getString(0);

            if (btadapter.isDiscovering()) {
                btadapter.cancelDiscovery();
            }

            BluetoothDevice device = btadapter.getRemoteDevice(addressDevice);
            boolean paired = false;

            Log.d("BluetoothPlugin", "Pairing with Bluetooth device with name " + device.getName()
                    + " and address " + device.getAddress());

            try {
                Method m = device.getClass().getMethod("createBond");
                paired = (Boolean) m.invoke(device);
            } catch (Exception e) {
                e.printStackTrace();
            }

            Log.d("BluetoothPlugin - " + ACTION_PAIR_BT, "Returning " + "Result: " + paired);
            result = new PluginResult(Status.OK, paired);
        } catch (Exception Ex) {
            Log.d("BluetoothPlugin - " + ACTION_PAIR_BT, "Got Exception " + Ex.getMessage());
            result = new PluginResult(Status.ERROR);
        }

    } else if (ACTION_UNPAIR_BT.equals(action)) {
        try {
            Log.d("BluetoothPlugin", "We're in " + ACTION_UNPAIR_BT);

            String addressDevice = arg1.getString(0);

            if (btadapter.isDiscovering()) {
                btadapter.cancelDiscovery();
            }

            BluetoothDevice device = btadapter.getRemoteDevice(addressDevice);
            boolean unpaired = false;

            Log.d("BluetoothPlugin", "Unpairing Bluetooth device with " + device.getName() + " and address "
                    + device.getAddress());

            try {
                Method m = device.getClass().getMethod("removeBond");
                unpaired = (Boolean) m.invoke(device);
            } catch (Exception e) {
                e.printStackTrace();
            }

            Log.d("BluetoothPlugin - " + ACTION_UNPAIR_BT, "Returning " + "Result: " + unpaired);
            result = new PluginResult(Status.OK, unpaired);
        } catch (Exception Ex) {
            Log.d("BluetoothPlugin - " + ACTION_UNPAIR_BT, "Got Exception " + Ex.getMessage());
            result = new PluginResult(Status.ERROR);
        }

    } else if (ACTION_LIST_BOUND_DEVICES.equals(action)) {
        try {
            Log.d("BluetoothPlugin", "We're in " + ACTION_LIST_BOUND_DEVICES);

            Log.d("BluetoothPlugin", "Getting paired devices...");
            Set<BluetoothDevice> pairedDevices = btadapter.getBondedDevices();
            int count = 0;
            String resultBoundDevices = "[ ";
            if (pairedDevices.size() > 0) {
                for (BluetoothDevice device : pairedDevices) {
                    Log.i("BluetoothPlugin",
                            device.getName() + " " + device.getAddress() + " " + device.getBondState());

                    if ((device.getName() != null) && (device.getBluetoothClass() != null)) {
                        resultBoundDevices = resultBoundDevices + " { \"name\" : \"" + device.getName() + "\" ,"
                                + "\"address\" : \"" + device.getAddress() + "\" ," + "\"class\" : \""
                                + device.getBluetoothClass().getDeviceClass() + "\" }";
                        if (count < pairedDevices.size() - 1)
                            resultBoundDevices = resultBoundDevices + ",";
                    } else
                        Log.i("BluetoothPlugin",
                                device.getName() + " Problems retrieving attributes. Device not added ");
                    count++;
                }

            }

            resultBoundDevices = resultBoundDevices + "] ";

            Log.d("BluetoothPlugin - " + ACTION_LIST_BOUND_DEVICES, "Returning " + resultBoundDevices);
            result = new PluginResult(Status.OK, resultBoundDevices);

        } catch (Exception Ex) {
            Log.d("BluetoothPlugin - " + ACTION_LIST_BOUND_DEVICES, "Got Exception " + Ex.getMessage());
            result = new PluginResult(Status.ERROR);
        }

    } else if (ACTION_STOP_DISCOVERING_BT.equals(action)) {
        try {
            Log.d("BluetoothPlugin", "We're in " + ACTION_STOP_DISCOVERING_BT);

            boolean stopped = true;

            Log.d("BluetoothPlugin", "Stop Discovering Bluetooth Devices...");

            if (btadapter.isDiscovering()) {
                Log.i("BluetoothPlugin", "Stop discovery...");
                stopped = btadapter.cancelDiscovery();
                discovering = false;
            }

            Log.d("BluetoothPlugin - " + ACTION_STOP_DISCOVERING_BT, "Returning " + "Result: " + stopped);
            result = new PluginResult(Status.OK, stopped);
        } catch (Exception Ex) {
            Log.d("BluetoothPlugin - " + ACTION_STOP_DISCOVERING_BT, "Got Exception " + Ex.getMessage());
            result = new PluginResult(Status.ERROR);
        }

    } else if (ACTION_IS_BOUND_BT.equals(action)) {
        try {
            Log.d("BluetoothPlugin", "We're in " + ACTION_IS_BOUND_BT);
            String addressDevice = arg1.getString(0);
            BluetoothDevice device = btadapter.getRemoteDevice(addressDevice);
            Log.i("BluetoothPlugin", "BT Device in state " + device.getBondState());

            boolean state = false;

            if (device != null && device.getBondState() == 12)
                state = true;
            else
                state = false;

            Log.d("BluetoothPlugin", "Is Bound with " + device.getName() + " - address " + device.getAddress());

            Log.d("BluetoothPlugin - " + ACTION_IS_BOUND_BT, "Returning " + "Result: " + state);
            result = new PluginResult(Status.OK, state);

        } catch (Exception Ex) {
            Log.d("BluetoothPlugin - " + ACTION_IS_BOUND_BT, "Got Exception " + Ex.getMessage());
            result = new PluginResult(Status.ERROR);
        }

    } else if (ACTION_OPEN_SOCKET.equals(action)) {
        Log.d("BluetoothPlugin", "We're in " + ACTION_OPEN_SOCKET);
        try {
            String addressDevice = arg1.getString(0);
            openSocket(addressDevice);
            result = new PluginResult(Status.OK, "true");

        } catch (Exception Ex) {
            Log.d("BluetoothPlugin - " + ACTION_OPEN_SOCKET, "Got Exception " + Ex.getMessage());
            result = new PluginResult(Status.ERROR);
        }

    } else if (ACTION_MESSAGE_SOCKET.equals(action)) {
        Log.d("BluetoothPlugin", "We're in " + ACTION_MESSAGE_SOCKET);
        try {
            String msg = arg1.getString(0);
            sendData(msg);
            result = new PluginResult(Status.OK, "true");

        } catch (Exception Ex) {
            Log.d("BluetoothPlugin - " + ACTION_MESSAGE_SOCKET, "Got Exception " + Ex.getMessage());
            result = new PluginResult(Status.ERROR);
        }

    } else if (ACTION_CLOSE_SOCKET.equals(action)) {
        Log.d("BluetoothPlugin", "We're in " + ACTION_CLOSE_SOCKET);
        try {
            closeSocket();
            result = new PluginResult(Status.OK, "true");

        } catch (Exception Ex) {
            Log.d("BluetoothPlugin - " + ACTION_CLOSE_SOCKET, "Got Exception " + Ex.getMessage());
            result = new PluginResult(Status.ERROR);
        }

    } else if (ACTION_PING_SOCKET.equals(action)) {
        try {

            Log.d("BluetoothPlugin", "We're in " + ACTION_PING_SOCKET);

            String data = "{";
            data = data + "\"count\": " + Integer.toString(pingCount) + ",";

            String items = "";
            for (String item : pingData) {
                items = items + ",\"" + item + "\"";
            }

            data = data + "  \"data\" : [" + items.substring(1) + " ]";
            data = data + "}";

            result = new PluginResult(Status.OK, data);
        } catch (Exception Ex) {
            Log.d("BluetoothPlugin - " + ACTION_PING_SOCKET, "Got Exception " + Ex.getMessage());
            result = new PluginResult(Status.ERROR);
        }

    }

    else {
        result = new PluginResult(Status.INVALID_ACTION);
        Log.d("BluetoothPlugin", "Invalid action : " + action + " passed");
    }
    return result;
}

From source file:org.deviceconnect.android.deviceplugin.health.fragment.HealthCareDeviceSettingsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {

    mDeviceAdapter = new DeviceAdapter(getActivity(), createDeviceContainers());

    mRootView = inflater.inflate(R.layout.fragment_heart_rate_device_settings, null);
    final ListView listView = (ListView) mRootView.findViewById(R.id.device_list_view);
    mFooterView = inflater.inflate(R.layout.bluetooth_list_footer_view, null);

    // ???????//w  w w.j a  v  a2 s .com
    View headerView = inflater.inflate(R.layout.bluetooth_list_header_view, null);
    Button button = (Button) headerView.findViewById(R.id.button_scan);
    if (getManager().isScanning()) {
        button.setText(R.string.heart_rate_setting_button_stop);
    }
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onClickScanButton();
        }
    });
    listView.addHeaderView(headerView);
    listView.setAdapter(mDeviceAdapter);

    // Bluetooth?????ON/OFF?
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBluetoothAdapter != null) {
        mBluetoothSwitch = (Switch) mRootView.findViewById(R.id.switch_bluetooth);
        if (mBluetoothSwitch != null) {
            if (mBluetoothAdapter.isEnabled()) {
                mBluetoothSwitch.setChecked(true);
                mRootView.findViewById(R.id.text_bluetooth_settings).setVisibility(View.GONE);
                mRootView.findViewById(R.id.device_list_view).setVisibility(View.VISIBLE);
            } else {
                mBluetoothSwitch.setChecked(false);
                mRootView.findViewById(R.id.text_bluetooth_settings).setVisibility(View.VISIBLE);
                mRootView.findViewById(R.id.device_list_view).setVisibility(View.GONE);
            }
        }
        mBluetoothSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    mBluetoothAdapter.enable();
                    mBluetoothSwitch.setEnabled(false);
                } else {
                    mBluetoothAdapter.disable();
                    mBluetoothSwitch.setEnabled(false);
                }
            }
        });

        getManager().setOnBluetoothStateChangedListener(mBLEListener);
    }
    return mRootView;
}

From source file:com.hari.autotasx.GeofenceTransitionsIntentService.java

@Override
protected void onHandleIntent(Intent intent) {

    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
    if (geofencingEvent.hasError()) {
        String errorMessage = GeofenceErrorMessages.getErrorString(this, geofencingEvent.getErrorCode());
        // Log.e(TAG, errorMessage);
        return;/*from   w w  w  . jav  a 2s  .  co m*/
    }

    int geofenceTransition = geofencingEvent.getGeofenceTransition();
    int smsDb = 0;
    int wifiDb = 0;
    int silDb = 0;
    int RemDb = 0;
    int blueDb = 0;
    int carDb = 0;
    String remMsgDb = null;
    int RemDb_carPark = 0;
    String remMsgDb_carPark = null;
    //Creating database object to fetch values
    ManageDB autodb = new ManageDB(this);
    autodb.open();

    if (!CarParkService.car_flag_static) {
        Cursor cursor = autodb.getEntry(ActionFragment.geoFence);
        cursor.moveToFirst();

        //System.out.println("cursor count"+cursor.getCount());

        //Log.i("logcat",cursor.getString(0)+", "+cursor.getString(1)+" , "+cursor.getString(2));
        smsDb = cursor.getInt(5);
        wifiDb = cursor.getInt(6);
        silDb = cursor.getInt(7);
        RemDb = cursor.getInt(8);
        remMsgDb = cursor.getString(9);
        blueDb = cursor.getInt(10);
        carDb = cursor.getInt(11);

        cursor.close();

    } else {
        Cursor cursor_carpark = autodb.getEntryCarPark(CarParkService.geofence_carpark);
        cursor_carpark.moveToFirst();

        carDb = cursor_carpark.getInt(11);
        remMsgDb_carPark = cursor_carpark.getString(9);

        cursor_carpark.close();
    }
    autodb.close();

    //Checking Enter/Exit transitions
    if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER) {
        List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();
        String geofenceTransitionDetails = getGeofenceTransitionDetails(this, geofenceTransition,
                triggeringGeofences);
        System.out.println("smsdb" + smsDb);
        if (RemDb == 1) {
            sendNotification(geofenceTransitionDetails, remMsgDb);
        }
        if (carDb == 1) {
            sendNotification(geofenceTransitionDetails, remMsgDb_carPark);
        }
        //Perform actions if set on Actions set
        if (silDb == 1) {
            Toast.makeText(this, "silent", Toast.LENGTH_SHORT).show();
            AudioManager am = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
            am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);

        }

        if (wifiDb == 1) {
            WifiManager wifiManager = (WifiManager) getBaseContext().getSystemService(Context.WIFI_SERVICE);
            wifiManager.setWifiEnabled(true);
        }

        if (blueDb == 1) {
            BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
            if (!mBluetoothAdapter.isEnabled()) {
                mBluetoothAdapter.enable();
            }
        }
        if (smsDb == 1) {
            Toast.makeText(this, "inside sendsms()", Toast.LENGTH_SHORT).show();
            SmsManager sm = SmsManager.getDefault();
            System.out.printf("sm", sm);
            sm.sendTextMessage(ActionFragment.smsNo, null,
                    "Hi, I am in " + ActionFragment.geoFence.getNameLoc() + " now!!!!", null, null);
        }
        if (carDb == 1) {
            Intent mapIntent = new Intent(this, CarParkMap.class);
            mapIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }

    } else if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {
        List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();
        String geofenceTransitionDetails = getGeofenceTransitionDetails(this, geofenceTransition,
                triggeringGeofences);
        if (silDb == 1) {
            Toast.makeText(this, "general", Toast.LENGTH_SHORT).show();
            AudioManager am1 = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
            am1.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        }

        if (wifiDb == 1) {
            WifiManager wifiManager1 = (WifiManager) getBaseContext().getSystemService(Context.WIFI_SERVICE);
            wifiManager1.setWifiEnabled(false);
        }
        if (blueDb == 1) {
            BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
            if (mBluetoothAdapter.isEnabled()) {
                mBluetoothAdapter.disable();
            }
        }
        if (smsDb == 1) {
            Toast.makeText(this, "inside sendsms()", Toast.LENGTH_SHORT).show();
            SmsManager sm = SmsManager.getDefault();
            System.out.printf("smsNo :" + ActionFragment.smsNo);
            //fetch
            sm.sendTextMessage(ActionFragment.smsNo, null,
                    "Hi, I am outside " + ActionFragment.geoFence.getNameLoc() + " now !!!", null, null);
        }
        if (RemDb == 1) {
            sendNotification(geofenceTransitionDetails, remMsgDb);
        }

    }

}