我编写的用于在启用蓝牙时禁用蓝牙的服务崩溃。
///////////////////////////////// 服务 //////////////// ///////////////
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent startServiceIntent = new Intent(context, Bluetoothservice.class);
context.startService(startServiceIntent);
if(intent.getAction().equals(BluetoothAdapter.ACTION_STATE_CHANGED)){
BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
if (bluetooth.getState() == BluetoothAdapter.STATE_ON
|| bluetooth.getState() == BluetoothAdapter.STATE_TURNING_ON) {
bluetooth.disable();
}
return;
}
///////////////////////////////// 接收者 //////////////// ////////////////
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
IntentFilter filterb = new IntentFilter(
BluetoothAdapter.ACTION_STATE_CHANGED);
BroadcastReceiver mreceiverb = new Broadcastreceiver();
registerReceiver(mreceiverb, filterb);
return super.onStartCommand(intent, flags, startId);
}
//////////////////////////// Logcat /////////////////////////////////////////////////////////////////////// ////////////////
E/AndroidRuntime( 8759): FATAL EXCEPTION: main
E/AndroidRuntime( 8759): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.bluetooth.adapter.action.STATE_CHANGED flg=0x10000010 (has extras) } in com.teststopper.StatusReceiver@407290f8
E/AndroidRuntime( 8759): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:734)
E/AndroidRuntime( 8759): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 8759): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 8759): at android.os.Looper.loop(Looper.java:132)
E/AndroidRuntime( 8759): at android.app.ActivityThread.main(ActivityThread.java:4126)
E/AndroidRuntime( 8759): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 8759): at java.lang.reflect.Method.invoke(Method.java:491)
E/AndroidRuntime( 8759): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
E/AndroidRuntime( 8759): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
E/AndroidRuntime( 8759): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 8759): Caused by: java.lang.SecurityException: Calling uid 10099 gave packageandroid which is owned by uid 1000
E/AndroidRuntime( 8759): at android.os.Parcel.readException(Parcel.java:1321)
E/AndroidRuntime( 8759): at android.os.Parcel.readException(Parcel.java:1275)
E/AndroidRuntime( 8759): at android.bluetooth.IBluetooth$Stub$Proxy.disable(IBluetooth.java:806)
E/AndroidRuntime( 8759): at android.bluetooth.BluetoothAdapter.disable(BluetoothAdapter.java:496)
E/AndroidRuntime( 8759): at com.teststopper.StatusReceiver.onReceive(StatusReceiver.java:17)
E/AndroidRuntime( 8759): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:725)
E/AndroidRuntime( 8759): ... 9 more
任何人都可以帮忙吗?