views:

45

answers:

2

I am wondering if a piece of hardware can be developed (probably over bluetooth for example) that could launch an existing android application on your device.

I can't seem to find any documentation on this kind of functionality.

Has anybody come across this?

+1  A: 

The theory behind this is the following:

  • You should generate a BroadcastIntent
  • This BroadcastIntent is received by a BroadcastReceiver
  • The BroadcastReceiver launches an application.

I've never used Bluetooth with Android, but there should be a Broadcast when someone tries to connect to you. You could listen to that.

Macarse
+1  A: 

Looks like there are ACTION_DISCOVERY_[STARTED|FINISHED] methods that you could register a broadcast receiver for. Link

To register the receiver, go into your project's AndroidManifest.xml and add the receiver tag and some permission tags:

    <application ...>

            <!-- Add your receiver class like so, and declare that you want to listen
                 for the DISCOVERY_FINISHED action -->
    <receiver android:name=".PUT_YOUR_CLASS_NAME_HERE(e.g. BluetoothReceiver)">
        <intent-filter>
            <action android:name="android.bluetooth.adapter.action.DISCOVERY_FINISHED" />
        </intent-filter>
    </receiver>

    </application>
    <!-- Add the permissions you might need here -->
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

you should then be able to create the BluetoothReceiver class and override the onReceive method.

Hamy