0

我在运行完美的 sonny erricson xperia Ray 2.3 android 上运行了以下服务。它旨在在用户尝试打开时自动禁用蓝牙和 WiFi。

这在启动时运行。

但是当我在 Galaxy tab 10.2 android 3.2 上运行时,它适用于 wifi,但在蓝牙上它会被强制关闭。

服务如下

IntentFilter filterb = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
BroadcastReceiver mReceiverb = new StatusReceiver();
registerReceiver(mReceiverb, filterb);

广播如下

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter.isEnabled()) {
    mBluetoothAdapter.disable();
}

许可如下

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

刚拿到logcat

E/AndroidRuntime( 9217): FATAL EXCEPTION: main
E/AndroidRuntime( 9217): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.bluetooth.adapter.action.STATE_CHANGED flg=0x10000010 (has extras) } in google.android.disable.StatusReceiver@407bbc40
E/AndroidRuntime( 9217):    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:734)
E/AndroidRuntime( 9217):    at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 9217):    at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 9217):    at android.os.Looper.loop(Looper.java:132)
E/AndroidRuntime( 9217):    at android.app.ActivityThread.main(ActivityThread.java:4126)
E/AndroidRuntime( 9217):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 9217):    at java.lang.reflect.Method.invoke(Method.java:491)
E/AndroidRuntime( 9217):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
E/AndroidRuntime( 9217):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
E/AndroidRuntime( 9217):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 9217): Caused by: java.lang.SecurityException: Calling uid 10097 gave packageandroid which is owned by uid 1000
E/AndroidRuntime( 9217):    at android.os.Parcel.readException(Parcel.java:1321)
E/AndroidRuntime( 9217):    at android.os.Parcel.readException(Parcel.java:1275)
E/AndroidRuntime( 9217):    at android.bluetooth.IBluetooth$Stub$Proxy.disable(IBluetooth.java:806)
E/AndroidRuntime( 9217):    at android.bluetooth.BluetoothAdapter.disable(BluetoothAdapter.java:496)
E/AndroidRuntime( 9217):    at google.android.disable.StatusReceiver.onReceive(StatusReceiver.java:26)
E/AndroidRuntime( 9217):    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:725)
E/AndroidRuntime( 9217):    ... 9 more
4

1 回答 1

0

Android 参考声明您不应在没有明确用户操作的情况下调用 BluetoothAdapter.disable()。这意味着您不应在设备启动时自动调用此方法。这可能是您的错误的原因。

参考: http: //developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#disable ()

于 2012-06-27T07:25:00.700 回答