自动启动蓝牙和wifi
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.cchen.connect" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <receiver android:name=".ActionReceiver"> <intent-filter> <action android:name="android.intent.action.USER_PRESENT"/> </intent-filter> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> </intent-filter> </receiver> </application> </manifest>
package com.cchen.connect; import android.bluetooth.BluetoothAdapter; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.net.wifi.WifiManager; import android.util.Log; public class ActionReceiver extends BroadcastReceiver{ static final String LOG_TAG = "ActionReceiver"; private BluetoothAdapter blueAdapter; @Override public void onReceive(Context context, Intent intentIn) { Log.d(LOG_TAG, "ACTION = " + intentIn.getAction()); String action = intentIn.getAction(); if (Intent.ACTION_USER_PRESENT.equals(action) || Intent.ACTION_BOOT_COMPLETED.equals(action) ) { blueAdapter = BluetoothAdapter.getDefaultAdapter(); if(!blueAdapter.isEnabled()){ blueAdapter.enable(); } WifiManager wifiMgr = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); int wifiState = wifiMgr.getWifiState(); if(wifiState == WifiManager.WIFI_STATE_DISABLED) { wifiMgr.setWifiEnabled(true); } Log.d(LOG_TAG, "========== UNLOCKINTENT " + blueAdapter.isEnabled() + wifiMgr.getWifiState()); } } }
相关推荐
80296330 2020-09-15
SeetyST 2020-08-13
张俊杰 2020-08-02
浅梦墨汐 2020-07-28
北落不吉 2020-06-27
棋牌游戏开发 2020-06-11
greenpepper 2020-06-11
greenpepper 2020-06-13
seek 2020-06-10
dotstar 2020-06-02
hushijiao 2020-05-17
浅梦墨汐 2020-05-12
chinaycheng 2020-05-06
sixforone 2020-05-06
海豚的成长日记 2020-05-04
greenpepper 2020-04-29
greenpepper 2020-04-22
海豚的成长日记 2020-01-12