Wednesday, June 27, 2012

How to route a mono sound from an android device to a handset/handfree

Today i was doing an RnD to route a mono sound from an android device to a handsfree/handset and after googling many things and trying out a few i was able to come up with a simple solution using BluetoothHandsfree profile.


Here is a code snippet:
<manifest>

<uses-permission android:name="
android.permission.MODIFY_AUDIO_SETTINGS" />
</manifest>

.................

BluetoothAdapter mBluetoothAdapter;
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
toast("Device does not support Bluetooth");
} else {
toast("Bluetooth is supported");
if (!mBluetoothAdapter.isEnabled()) {
toast("Requesting for Bluetooth");
Intent discoverableIntent = new Intent(
BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(
BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivityForResult(discoverableIntent, REQUEST_ENABLE_BT);
} else {
toast("Bluetooth Enabled");
}
}

mBluetoothAdapter.getProfileProxy(getApplicationContext(),
mProfileListener, BluetoothProfile.HEADSET);

private BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() {
public void onServiceConnected(int profile, BluetoothProfile proxy) {
if (profile == BluetoothProfile.HEADSET) {
mBluetoothHeadset = (BluetoothHeadset) proxy;
Log.i(tag, "***** Headset proxy obtained *****");
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);

audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.startBluetoothSco();
audioManager.setBluetoothScoOn(true);

short[] soundData = new short[8000 * 20];
for (int iii = 0; iii < 20 * 8000; iii++) {
soundData[iii] = 32767; // High Note
iii++;
soundData[iii] = 32767; // High Note
iii++;
soundData[iii] = -32768; // Low Note
iii++;
soundData[iii] = -32768; // Low Note
}

AudioTrack audioTrack = new AudioTrack(
AudioManager.STREAM_VOICE_CALL, 8000,
AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT, soundData.length
* Short.SIZE, AudioTrack.MODE_STATIC);
audioTrack.write(soundData, 0, soundData.length);
audioTrack.play();
}
}

public void onServiceDisconnected(int profile) {
if (profile == BluetoothProfile.HEADSET) {
mBluetoothHeadset = null;
Log.i(tag, "***** Headset Disconnected *****");
}
}
};

After running this code in an activity a buzz sound can be listened in a headset/handsfree.




4 P's vs. 4 C's

Received a mail today and loved it...following are the words of wisdom:

  • Not PRODUCT, but CONSUMER
You have to understand what the consumers' wants and needs are. Times have changed and you can no longer sell whatever you can make. The product characteristics have to match the specifics of what someone wants to buy. And part of what the consumer is buying is the personal "buying experience."
  • Not PRICE, but COST
Understand the consumer's cost to satisfy the want or need. The product price may be only one part of the consumer's cost structure. Often it is the cost of time to drive somewhere, the cost of conscience of what you buy, the cost of guilt for not treating the kids, the investment a consumer is willing to make to avoid risk, etc.
  • Not PLACE, but CONVENIENCE
As above, turn the standard logic around. Think convenience of the buying experience and then relate that to a delivery mechanism. Consider all possible definitions of "convenience" as it relates to satisfying the consumer's wants and needs. Convenience may include aspects of the physical or virtual location, access ease, transaction service time, and hours of availability.
  • Not PROMOTION, but COMMUNICATION
Communicate,many mediums working together to present a unified message with a feedback mechanism to make the communication two-way. And be sure to include an understanding of non-traditional mediums, such as word of mouth and how it can influence your position in the consumer's mind. How many ways can a customer hear (or see) the same message through the course of the day, each message reinforcing the earlier images?