I am trying a code that shows a message or a toast when I connect my headphones to my mobile. But the code is not working, it does not show any toast when I am connecting to my mobile. Here is the code:
Class File
 public class Record extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent arg1) {
    // TODO Auto-generated method stub
    Toast.makeText(context, "Headphones Connected", Toast.LENGTH_LONG).show();
    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(2000);
}
Manifest File
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.brodcastrecieverexample.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <receiver android:name="com.example.brodcastrecieverexample.Record">
    <intent-filter>
        <action android:name="android.intent.action.HEADSET_PLUG"/>
        <action android:name="android.media.SCO_AUDIO_STATE_CHANGED"/>
    </intent-filter>
    </receiver>
</application>
I think there is something missing in the manifest file, i did all the searching but could not find what is missing.