0

The service I wrote to disable Bluetooth when ever it gets enabled crashes.

///////////////////////////////// service ////////////////////////////////

 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;
            }

///////////////////////////////// Receiver /////////////////////////////////

@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

Can anyone help?

Bo.
  • 2,547
  • 3
  • 24
  • 36
Loshi
  • 221
  • 1
  • 5
  • 19

2 Answers2

0

You must specify each feature in a separate <uses-feature> element, so if your application requires multiple features, it would declare multiple <uses-feature> elements.

For example, an application that requires both Bluetooth and camera features in the device would declare these two elements:

<uses-feature android:name="android.hardware.bluetooth" />
<uses-feature android:name="android.hardware.camera" />

also check you have added

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

BLUETOOTH   Allows applications to connect to paired bluetooth devices
BLUETOOTH_ADMIN Allows applications to discover and pair bluetooth devices

Special handling for Bluetooth feature

Padma Kumar
  • 19,893
  • 17
  • 73
  • 130
0

As I stated in the answer to your other question, you should not disable the bluetooth adapter without explicit user consent.

Community
  • 1
  • 1
Ian Newson
  • 7,679
  • 2
  • 47
  • 80
  • Even so, you should not expect this to work as the documentation explicitly states that you should not do what you're trying to do. – Ian Newson Jun 29 '12 at 07:39
  • @Loshi Sounds good. Your options are to either create a custom Android build to give you complete control over the OS (this will be fairly difficult) or to use an enterprise management tool (i.e. MDM). – Ian Newson Jun 29 '12 at 08:39
  • anw, thnx mate..... hope u can either help me with this one.... http://stackoverflow.com/questions/11259400/android-code-to-kill-a-specific-process-kills-the-other-processors-runs-at-the – Loshi Jun 29 '12 at 09:36