I am trying to write what I think is a very simple application just to check for when the head phone is plugged in and then mute the notification sounds. I am a bit confused on the broadcast receiver, can I have a app that is just that class and have it listen for when that action happens, do I need a service running as well?
Here is my code: package com.blee.checkheadphone; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.media.AudioManager; import android.os.Bundle; import android.util.Log; public class CheckheadphoneManager extends BroadcastReceiver { public static final String LOG_TAG = "Checkheadphone"; Context mContext; private AudioManager mAudioManager; private final String HEADSET_ACTION = "android.intent.action.HEADSET_PLUG"; @Override public void onReceive(Context arg0, Intent arg1) { mContext = arg0; Log.v(LOG_TAG, "Intent captured"); String action = arg1.getAction(); action.equalsIgnoreCase(HEADSET_ACTION); Bundle bundle = arg1.getExtras(); int headValue = bundle.getInt("state"); mAudioManager = (AudioManager)arg0.getSystemService(Context.AUDIO_SERVICE); if(headValue==0){ //System.out.println("Headphone unplugged"); Log.v(LOG_TAG, "Headphone unplugged"); //mAudioManager.setSpeakerphoneOn(false); mAudioManager.setStreamMute(AudioManager.STREAM_NOTIFICATION, false); }else{ //mAudioManager.setSpeakerphoneOn(true); //System.out.println("Headphone plugged"); Log.v(LOG_TAG, "Headphone plugged"); mAudioManager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true); } } } And my manifest: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.blee.checkheadphone" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="10" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"></uses- permission> <application android:icon="@drawable/icon" android:label="@string/ app_name"> <receiver android:name="CheckheadphoneManager" android:enabled="true" > <intent-filter> <action android:name="android.intent.action.HEADSET_PLUG" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </receiver> </application> </manifest> When I watch logcat, nothing shows for my app. Any help will be appreciated. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en