2013-08-28 186 views
5

是否可以在沒有用戶干預的情況下從ADB啓動藍牙? 我試過了:從ADB啓動藍牙或啓動?

am start -a android.bluetooth.adapter.action.REQUEST_ENABLE 

但這需要用戶按下ok。並且:

service call bluetooth 3 

什麼也沒做。 在init.rc中啓用bluetoothd服務也不起作用。

service bluetoothd /system/bin/bluetoothd -n 
    class main 
    socket bluetooth stream 660 bluetooth bluetooth 
    socket dbus_bluetooth stream 660 bluetooth bluetooth 
    # init.rc does not yet support applying capabilities, so run as root and 
    # let bluetoothd drop uid to bluetooth with the right linux capabilities 
    group bluetooth net_bt_admin misc 
    enabled 

而且我更希望亞行的命令。 (如果有人想知道我需要它進行FCC測試。)

回答

3

如果它適用於您,應用程序可以輕鬆更改藍牙狀態。該代碼是很簡單的,我敢肯定你熟悉吧:

BluetoothAdapter.getDefaultAdapter().enable() 

這可能是一個「無頭」應用程序只偵聽特定意圖的服務。你可以安裝它,然後廣播激活者的意圖。

如果您希望應用程序未出現在應用程序「抽屜」中(僅在設置 - >應用程序中),請從AndroidManifest.xml文件中刪除啓動器和主要意圖過濾器。也就是說,刪除這些:

<intent-filter> 
    <action android:name="android.intent.action.MAIN" /> 
    <category android:name="android.intent.category.LAUNCHER" /> 
</intent-filter> 

從這時起,你就可以開始你的清單文件中定義了它的意圖應用程序/服務。例如,您可以創建並註冊的意圖過濾器與動作com.company.service.bluetooth.ON服務,並與亞行命令來啓動它:

am startservice -a com.company.service.bluetooth.ON 

似乎沒有被任何其他方式做到這一點,如果手機沒有根。如果生根,service call bluetooth 3應該工作。

本教程描述了一個工作解決方案:How to launch an Android app from adb - And toggle bluetooth。他們使用這個程序:Bluetooth On/Off Toggle App.

+0

是的,我想爲此做一個應用程序作爲最後的手段(BluetoothON應用程序和BluetoothOFF應用程序)。是否可以從應用程序抽屜中隱藏應用程序(我們在4.1.2)?然後使用「adb shell am start」來啓動它。 –

+0

更新了隱藏信息的答案 – allprog

4

在一個植根設備

adb shell service call bluetooth_manager 8 

爲我工作。

+0

不幸的是,這實際上似乎需要一個紮根設備 – raphinesse

+0

@raphinesse是的,我知道,這就是爲什麼我的答案中的第一行是「在根植設備上」 – Danw25