-1

我正在尝试开发由启动接收器启动的服务,如果启用了 wifi 或蓝牙会自动禁用它。

请帮帮我

谢谢你

4

1 回答 1

2

在清单中

<receiver android:name=".BootTimeServiceStarter" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

并在您的类文件中执行以下操作

 public class BootTimeServiceStarter extends BroadcastReceiver 
    {

        @Override
        public void onReceive(Context context, Intent intent)
        {


    BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
            if (bluetooth.getState() == BluetoothAdapter.STATE_ON
                    || bluetooth.getState() == BluetoothAdapter.STATE_TURNING_ON) {
                    bluetooth.disable();
            }
    WifiManager wifiManager = (WifiManager) context
                    .getSystemService(Context.WIFI_SERVICE);
            if (wifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED
                    || wifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLING) {
                wifiManager.setWifiEnabled(false);
            }


            }
    }
于 2012-06-26T09:36:05.837 回答