Example usage for android.bluetooth BluetoothAdapter ACTION_STATE_CHANGED

List of usage examples for android.bluetooth BluetoothAdapter ACTION_STATE_CHANGED

Introduction

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

Prototype

String ACTION_STATE_CHANGED

To view the source code for android.bluetooth BluetoothAdapter ACTION_STATE_CHANGED.

Click Source Link

Document

Broadcast Action: The state of the local Bluetooth adapter has been changed.

Usage

From source file:org.bcsphere.activity.BCPage.java

@Override
public void onStart() {
    super.onStart();

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    mActivity.registerReceiver(mReceiver, intentFilter);
}

From source file:com.mattprecious.notisync.service.SecondaryService.java

@Override
public void onCreate() {
    super.onCreate();

    broadcastManager = LocalBroadcastManager.getInstance(this);
    textMessages = Maps.newLinkedHashMap();
    gtalkMessages = Maps.newLinkedHashMap();

    running = true;//from   www.  java 2 s  . c  o  m
    broadcastManager.sendBroadcast(new Intent(ServiceActions.ACTION_SERVICE_STARTED));

    if (bluetoothAdapter == null) {
        stopSelf();
        return;
    }

    dbAdapter = new DbAdapter(this);
    notificationsDbAdapter = new NotificationDatabaseAdapter(this);
    connectedDeviceName = null;

    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    startForeground(NOTIFICATION_ID_RUNNING, buildRunningNotification());

    bluetoothService = new BluetoothService(this, new SecondaryHandler(this), true);

    broadcastManager.registerReceiver(timerReceiver, new IntentFilter(ServiceActions.ACTION_UPDATE_TIMER));
    broadcastManager.registerReceiver(sendMessageReceiver, new IntentFilter(ACTION_SEND_MESSAGE));
    broadcastManager.registerReceiver(devToolsMessageReceiver,
            new IntentFilter(DevToolsActivity.ACTION_RECEIVE_MESSAGE));

    registerReceiver(bluetoothStateReceiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
    registerReceiver(textNotificationDeletedReceiver, new IntentFilter(ACTION_TEXT_NOTIFICATION_DELETED));
    registerReceiver(gtalkNotificationDeletedReceiver, new IntentFilter(ACTION_GTALK_NOTIFICATION_DELETED));

    updateTimer();
}

From source file:com.javadog.bluetoothproximitylock.BluetoothFragment.java

/**
 * Initializes object references and performs some other set-up tasks.
 */// w  w  w.j a  v  a2  s . c o  m
private void initialize() {
    //Get a reference to the user preferences editor
    userPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());

    //Get fresh references to our views
    serviceToggle = new BetterCompoundButton<>(getActivity(),
            (Switch) getView().findViewById(R.id.button_bt_service_start_stop));
    signalStrengthView = (TextView) getView().findViewById(R.id.bt_signal_strength);
    deviceChooser = (Spinner) getView().findViewById(R.id.bt_device_chooser);
    lockDistance = (Spinner) getView().findViewById(R.id.bt_lock_distances); //TODO: This doesn't do anything yet.
    lockInstantly = new BetterCompoundButton<>(getActivity(),
            (CheckBox) getView().findViewById(R.id.bt_lock_instantly));
    refreshIntervalSpinner = (Spinner) getView().findViewById(R.id.bt_refresh_interval);

    //Get a reference to the local broadcast manager, and specify which intent actions we want to listen for
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getActivity().getApplicationContext());
    IntentFilter filter = new IntentFilter();
    filter.addAction(SignalReaderService.ACTION_SIGNAL_STRENGTH_UPDATE);
    filter.addAction(SignalReaderService.ACTION_UNBIND_SERVICE);

    //Instantiate the ssReceiver if it's not already, then register it with the broadcast manager
    if (ssReceiver == null) {
        ssReceiver = new LocalBroadcastReceiver();
    }
    manager.registerReceiver(ssReceiver, filter);

    //Check whether device admin privileges are active, and show a dialog if not
    DevicePolicyManager dpm = (DevicePolicyManager) getActivity()
            .getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (!dpm.isAdminActive(new ComponentName(getActivity().getApplicationContext(), DeviceLockManager.class))) {
        AdminDialogFragment adminDialogFragment = new AdminDialogFragment();
        adminDialogFragment.setCancelable(false);
        adminDialogFragment.show(getFragmentManager(), "needsAdmin");
    }

    populateBtDevices();

    //Start the device chooser in a disabled state if Bluetooth is disabled
    if (BluetoothAdapter.getDefaultAdapter().isEnabled()) {
        deviceChooser.setEnabled(true);
    } else {
        deviceChooser.setEnabled(false);
    }

    //Register a listener with the system to get updates about changes to Bluetooth state
    if (btStateReceiver == null) {
        btStateReceiver = new BluetoothStateReceiver();
    }
    IntentFilter btFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
    getActivity().registerReceiver(btStateReceiver, btFilter);

    /**
     * Will attach the Activity to the Service as soon as the service is started.
     */
    serviceConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            serviceBound = true;
            updateBtServiceUI();
        }

        @Override
        public void onServiceDisconnected(ComponentName componentName) {
            //This should never be called because our service resides in the same process.
        }
    };
}

From source file:org.physical_web.physicalweb.FatBeaconBroadcastService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    fetchBroadcastData(intent);//from ww w .ja v a 2s  .  c  o  m
    if (mDisplayInfo == null || data == null) {
        stopSelf();
        return START_STICKY;
    }
    IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
    registerReceiver(mReceiver, filter);
    broadcastUrl();
    initGattServer();
    return START_STICKY;
}

From source file:com.aware.plugin.polarhrm.Plugin.java

@Override
public void onCreate() {
    super.onCreate();
    TAG = "PolarHRM";

    CONTEXT_PRODUCER = new Aware_Plugin.ContextProducer() {
        @Override//from  ww  w. jav a  2 s .  co m
        public void onContext() {
            Intent heartRate = new Intent(ACTION_AWARE_POLAR_HEARTRATE);
            sendBroadcast(heartRate);
        }
    };

    DATABASE_TABLES = PolarHRM_Provider.DATABASE_TABLES;
    TABLES_FIELDS = PolarHRM_Provider.TABLES_FIELDS;
    CONTEXT_URIS = new Uri[] { PolarHRM_Data.CONTENT_URI, PolarHRM_Profile.CONTENT_URI };

    notManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationBuilder = new NotificationCompat.Builder(this);

    IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
    registerReceiver(btStateListener, filter);

    prefs = getSharedPreferences(getPackageName(), MODE_MULTI_PROCESS);

    if (btAdapter != null && !btAdapter.isEnabled()) {
        Intent makeEnabled = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        makeEnabled.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
        startActivity(makeEnabled);
    }

    updater = new Timer();
    updater.scheduleAtFixedRate(updateHR, 0, 2000);

    if (!prefs.contains("age")) {
        Intent hrm_params = new Intent(getApplicationContext(), Settings.class);
        hrm_params.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(hrm_params);
    } else {
        algorithm = new Algorithm(prefs.getInt("age", 25), prefs.getInt("rhr", 70));
        SparseArray<double[]> hr_zones = algorithm.getZones();

        ContentValues rowData = new ContentValues();
        rowData.put(PolarHRM_Profile.TIMESTAMP, System.currentTimeMillis());
        rowData.put(PolarHRM_Profile.DEVICE_ID,
                Aware.getSetting(getContentResolver(), Aware_Preferences.DEVICE_ID));
        rowData.put(PolarHRM_Profile.AGE, prefs.getInt("age", 25));
        rowData.put(PolarHRM_Profile.RESTING_HR, prefs.getInt("rhr", 70));
        rowData.put(PolarHRM_Profile.RECOVERY_MIN, hr_zones.get(0)[0]);
        rowData.put(PolarHRM_Profile.RECOVERY_MAX, hr_zones.get(0)[1]);
        rowData.put(PolarHRM_Profile.AEROBIC_MIN, hr_zones.get(1)[0]);
        rowData.put(PolarHRM_Profile.AEROBIC_MAX, hr_zones.get(1)[1]);
        rowData.put(PolarHRM_Profile.ANAEROBIC_MIN, hr_zones.get(2)[0]);
        rowData.put(PolarHRM_Profile.ANAEROBIC_MAX, hr_zones.get(2)[1]);
        rowData.put(PolarHRM_Profile.RED_LINE_MIN, hr_zones.get(3)[0]);
        rowData.put(PolarHRM_Profile.RED_LINE_MAX, hr_zones.get(3)[1]);

        getContentResolver().insert(PolarHRM_Profile.CONTENT_URI, rowData);
    }

    showUI();
}

From source file:com.piusvelte.taplock.client.core.TapLockService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null) {
        String action = intent.getAction();
        if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
            int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF);
            if (state == BluetoothAdapter.STATE_ON) {
                if (mStartedBT) {
                    if (mUIInterface != null) {
                        try {
                            mUIInterface.setMessage("Bluetooth enabled");
                        } catch (RemoteException e) {
                            Log.e(TAG, e.getMessage());
                        }//from w ww .j  a  v a  2s  .c  o  m
                    }
                    if ((mQueueAddress != null) && (mQueueState != null))
                        requestWrite(mQueueAddress, mQueueState, mQueuePassphrase);
                    else if (mRequestDiscovery && !mBtAdapter.isDiscovering())
                        mBtAdapter.startDiscovery();
                    else if (mUIInterface != null) {
                        try {
                            mUIInterface.setBluetoothEnabled();
                        } catch (RemoteException e) {
                            Log.e(TAG, e.getMessage());
                        }
                    }
                }
            } else if (state == BluetoothAdapter.STATE_TURNING_OFF) {
                if (mUIInterface != null) {
                    try {
                        mUIInterface.setMessage("Bluetooth disabled");
                    } catch (RemoteException e) {
                        Log.e(TAG, e.getMessage());
                    }
                }
                stopThreads();
            }
        } else if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            // Get the BluetoothDevice object from the Intent
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
                // connect if configured
                String address = device.getAddress();
                for (JSONObject deviceJObj : mDevices) {
                    try {
                        if (deviceJObj.getString(KEY_ADDRESS).equals(address)) {
                            // if queued
                            mDeviceFound = (mQueueAddress != null) && mQueueAddress.equals(address)
                                    && (mQueueState != null);
                            break;
                        }
                    } catch (JSONException e) {
                        Log.e(TAG, e.getMessage());
                    }
                }
            } else if (mRequestDiscovery && (mUIInterface != null)) {
                String unpairedDevice = TapLock
                        .createDevice(device.getName(), device.getAddress(), DEFAULT_PASSPHRASE).toString();
                try {
                    mUIInterface.setUnpairedDevice(unpairedDevice);
                } catch (RemoteException e) {
                    Log.e(TAG, e.getMessage());
                }
            }
        } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            if (mDeviceFound) {
                requestWrite(mQueueAddress, mQueueState, mQueuePassphrase);
                mDeviceFound = false;
            } else if (mRequestDiscovery) {
                mRequestDiscovery = false;
                if (mUIInterface != null) {
                    try {
                        mUIInterface.setDiscoveryFinished();
                    } catch (RemoteException e) {
                        Log.e(TAG, e.toString());
                    }
                }
            }
        } else if (ACTION_TOGGLE.equals(action) && intent.hasExtra(EXTRA_DEVICE_ADDRESS)) {
            String address = intent.getStringExtra(EXTRA_DEVICE_ADDRESS);
            requestWrite(address, ACTION_TOGGLE, null);
        } else if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
            // create widget
            if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) {
                int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                        AppWidgetManager.INVALID_APPWIDGET_ID);
                if (intent.hasExtra(EXTRA_DEVICE_NAME)) {
                    // add a widget
                    String deviceName = intent.getStringExtra(EXTRA_DEVICE_NAME);
                    for (int i = 0, l = mDevices.size(); i < l; i++) {
                        String name = null;
                        try {
                            name = mDevices.get(i).getString(KEY_NAME);
                        } catch (JSONException e1) {
                            e1.printStackTrace();
                        }
                        if ((name != null) && name.equals(deviceName)) {
                            JSONObject deviceJObj = mDevices.remove(i);
                            JSONArray widgetsJArr;
                            if (deviceJObj.has(KEY_WIDGETS)) {
                                try {
                                    widgetsJArr = deviceJObj.getJSONArray(KEY_WIDGETS);
                                } catch (JSONException e) {
                                    widgetsJArr = new JSONArray();
                                }
                            } else
                                widgetsJArr = new JSONArray();
                            widgetsJArr.put(appWidgetId);
                            try {
                                deviceJObj.put(KEY_WIDGETS, widgetsJArr);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            mDevices.add(i, deviceJObj);
                            TapLock.storeDevices(this, getSharedPreferences(KEY_PREFS, MODE_PRIVATE), mDevices);
                            break;
                        }
                    }
                }
                buildWidget(appWidgetId);
            } else if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS)) {
                int[] appWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
                if (appWidgetIds != null) {
                    for (int appWidgetId : appWidgetIds)
                        buildWidget(appWidgetId);
                }
            }
        } else if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
            int appWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                    AppWidgetManager.INVALID_APPWIDGET_ID);
            Log.d(TAG, "delete appWidgetId: " + appWidgetId);
            for (int i = 0, l = mDevices.size(); i < l; i++) {
                JSONObject deviceJObj = mDevices.get(i);
                if (deviceJObj.has(KEY_WIDGETS)) {
                    JSONArray widgetsJArr = null;
                    try {
                        widgetsJArr = deviceJObj.getJSONArray(KEY_WIDGETS);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    if (widgetsJArr != null) {
                        boolean wasUpdated = false;
                        JSONArray newWidgetsJArr = new JSONArray();
                        for (int widgetIdx = 0, wdigetsLen = widgetsJArr
                                .length(); widgetIdx < wdigetsLen; widgetIdx++) {
                            int widgetId;
                            try {
                                widgetId = widgetsJArr.getInt(widgetIdx);
                            } catch (JSONException e) {
                                widgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
                                e.printStackTrace();
                            }
                            Log.d(TAG, "eval widgetId: " + widgetId);
                            if ((widgetId != AppWidgetManager.INVALID_APPWIDGET_ID)
                                    && (widgetId == appWidgetId)) {
                                Log.d(TAG, "skip: " + widgetId);
                                wasUpdated = true;
                            } else {
                                Log.d(TAG, "include: " + widgetId);
                                newWidgetsJArr.put(widgetId);
                            }
                        }
                        if (wasUpdated) {
                            try {
                                deviceJObj.put(KEY_WIDGETS, newWidgetsJArr);
                                mDevices.remove(i);
                                mDevices.add(i, deviceJObj);
                                TapLock.storeDevices(this, getSharedPreferences(KEY_PREFS, MODE_PRIVATE),
                                        mDevices);
                                Log.d(TAG, "stored: " + deviceJObj.toString());
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                } else {
                    JSONArray widgetsJArr = new JSONArray();
                    try {
                        deviceJObj.put(KEY_WIDGETS, widgetsJArr);
                        mDevices.remove(i);
                        mDevices.add(i, deviceJObj);
                        TapLock.storeDevices(this, getSharedPreferences(KEY_PREFS, MODE_PRIVATE), mDevices);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
    return START_STICKY;
}

From source file:activities.GatewayActivity.java

@Override
public void onResume() {
    super.onResume();
    // Register the BroadcastReceiver
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    IntentFilter filter2 = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    IntentFilter filter3 = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
    IntentFilter filter4 = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
    registerReceiver(mReceiver, filter); // Don't forget to unregister during onDestroy
    registerReceiver(mReceiver, filter2); // Don't forget to unregister during onDestroy
    registerReceiver(mReceiver, filter3); // Don't forget to unregister during onDestroy
    registerReceiver(mReceiver, filter4); // Don't forget to unregister during onDestroy
}

From source file:de.unifreiburg.es.iLitIt.LighterBluetoothService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (mBluetoothChangeReceiver == null) {
        mBluetoothChangeReceiver = new BroadcastReceiver() {
            @Override/*from ww w. j  a v  a 2 s .co  m*/
            public void onReceive(Context context, Intent intent) {
                final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);

                switch (state) {
                case BluetoothAdapter.STATE_ON:
                    onStartCommand(null, 0, 0);
                    break;
                case BluetoothAdapter.STATE_OFF:
                    break;
                default:
                    break;
                }
            }
        };

        IntentFilter mif = new IntentFilter();
        mif.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
        registerReceiver(mBluetoothChangeReceiver, mif);
    }

    if (mSmartWatchAnnotationReceiver == null) {
        mSmartWatchAnnotationReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (mEventList == null)
                    return;

                String via = intent.getStringExtra("ess.imu_logger.libs.data_save.extra.annotationVia");
                mEventList.add(new CigaretteEvent(new Date(), via == null ? "intent" : via, null));
            }
        };

        // create watch ui intent listener
        IntentFilter filter = new IntentFilter("ess.imu_logger.libs.data_save.annotate");
        registerReceiver(mSmartWatchAnnotationReceiver, filter);
    }

    // For API level 18 and above, get a reference to BluetoothAdapter through
    // BluetoothManager.
    //if (serviceIsInitialized)
    //    return START_STICKY;

    mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    if (mBluetoothManager == null) {
        Log.e(TAG, "Unable to initialize BluetoothManager.");
        return START_NOT_STICKY;
    }

    mBluetoothAdapter = mBluetoothManager.getAdapter();
    if (mBluetoothAdapter == null) {
        Log.e(TAG, "Unable to obtain a BluetoothAdapter.");
        return START_NOT_STICKY;
    }

    // for DEBUGGING only
    // PreferenceManager.getDefaultSharedPreferences(this).edit().clear().apply();

    /** check if we are already bound to a device, if not start scanning for one */
    mBluetoothDeviceAddress = PreferenceManager.getDefaultSharedPreferences(this).getString(KEY_DEVICEADDR,
            null);
    mLastBatteryVoltage = PreferenceManager.getDefaultSharedPreferences(this).getFloat(KEY_BATVOLTAGE, 0.0f);
    mBatteryEmpty = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(KEY_BATEMTPY, false);

    super.onStartCommand(intent, flags, startId);

    /** load the stored events */
    if (mEventList == null) {
        mEventList = CigAnnotationWriter.readCigaretteList(this);

        mEventList.register(rCigAnnotationWriter);
        mEventList.register(rCigIntentBroadcaster);

    }

    /** set-up the location service, we need this to run here, since we need to
     *access the location whenever there is a chang to the cigarette model. */
    mLocationClient = new LocationClient(this, mLocationHandler, mLocationHandler);
    mEventList.register(new DelayedObserver(1000, mLocationHandler));

    /** start to scan for LE devices in the area */
    mHandler = new Handler(Looper.getMainLooper());
    mHandler.post(rStartLEScan);

    /** create a notification on a pending connection */
    PendingIntent i = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class),
            PendingIntent.FLAG_UPDATE_CURRENT);
    mNotification = (new NotificationCompat.Builder(this)).setContentText("downloading cigarette events")
            .setContentTitle("iLitIt").setSmallIcon(R.drawable.ic_cigarette_black).setProgress(0, 0, true)
            .setAutoCancel(true).setContentIntent(i).build();

    mLowBatteryWarning = (new NotificationCompat.Builder(this)).setContentTitle("iLitIt - battery low")
            .setContentText("replace battery as soons as possible").setSmallIcon(R.drawable.ic_launcher)
            .build();

    return START_STICKY;
}

From source file:org.deviceconnect.android.deviceplugin.heartrate.fragment.HeartRateDeviceSettingsFragment.java

/**
 * Register a BroadcastReceiver of Bluetooth event.
 *//*from ww  w . j  a v a  2 s  .  c  o  m*/
private void registerBluetoothFilter() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
    getActivity().registerReceiver(mSensorReceiver, filter, null, mHandler);
}

From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java

@Override
public void onReceive(Context context, Intent intent) {
    mComtext = context;//from w  w w.  j  a  v a2 s.  c  om
    String action = intent.getAction();
    Log.i("sai", "onReceive: " + action);

    super.onReceive(context, intent);

    if (ACTION_ON_QUARTER_HOUR.equals(action) || Intent.ACTION_DATE_CHANGED.equals(action)
            || Intent.ACTION_TIMEZONE_CHANGED.equals(action) || Intent.ACTION_TIME_CHANGED.equals(action)
            || Intent.ACTION_LOCALE_CHANGED.equals(action)) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        if (appWidgetManager != null) {
            int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
            for (int appWidgetId : appWidgetIds) {
                RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
                float ratio = WidgetUtils.getScaleRatio(context, null, appWidgetId);
                // SPRD for bug421127 add am/pm for widget
                WidgetUtils.setTimeFormat(widget,
                        (int) context.getResources().getDimension(R.dimen.widget_label_font_size),
                        R.id.the_clock);
                WidgetUtils.setClockSize(context, widget, ratio);
                //refreshAlarm(context, widget);
                appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget);
            }
        }
        if (!ACTION_ON_QUARTER_HOUR.equals(action)) {
            cancelAlarmOnQuarterHour(context);
        }
        startAlarmOnQuarterHour(context);
    }
    // cg sai.pan begin
    else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        if (appWidgetManager != null) {
            int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
            for (int appWidgetId : appWidgetIds) {
                RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
                refreshBtStatus(context, widget);
                appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget);
            }
        }
    } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
        int wifiStatus = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);
        Log.e("sai", "wifiStatus" + wifiStatus);
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        if (appWidgetManager != null) {
            int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
            for (int appWidgetId : appWidgetIds) {
                RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
                if (WifiManager.WIFI_STATE_ENABLED == wifiStatus
                        || WifiManager.WIFI_STATE_ENABLING == wifiStatus) {
                    widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_on);
                } else {
                    widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_off);
                }
                appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget);
            }
        }
    } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        if (appWidgetManager != null) {
            int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
            for (int appWidgetId : appWidgetIds) {
                RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
                refreshWifiStatus(context, widget);
            }
        }
    } else if ("android.net.conn.CONNECTIVITY_CHANGE".equals(action)) {
        if (isNetworkConnected(context)) {
            Log.e("sai", "isNetworkConnected true");
            requestLocation(context);
        } else {
            Log.e("sai", "isNetworkConnected false");
        }
    }
}