Android 2.3.3 service application runns clearly bu

2019-03-03 23:10发布

i have the following service running on the sonny erricson xperia Ray 2.3 android which runns perfectly. it is designed to automatically disable bluetooth and WiFi when ever the user try to switch on.

this runs on the boot.

But when i runs on the Galaxy tab 10.2 android 3.2 it works for wifi but on bluetooth it gets force closed.

Service is as follows

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

Broadcast is as follows

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

permission is given as follows

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

just got the 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

1条回答
倾城 Initia
2楼-- · 2019-03-03 23:49

The Android reference states that you should not call BluetoothAdapter.disable() without explicit user action. This means you should not call this method automatically when the device boots. This may be the reason for your error.

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

查看更多
登录 后发表回答