Android Open Source - AUXManager Headset Action Broadcast Receiver






From Project

Back to project page AUXManager.

License

The source code is released under:

GNU General Public License

If you think the Android project AUXManager listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.easysoft.auxmanager.receiver;
//  w ww.ja  v  a 2  s  . c  o m

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.util.Log;
import com.easysoft.auxmanager.service.AUXManagerService;
import com.easysoft.auxmanager.shared.Constants;
/**
 * Manages speaker behavior depended on headset activity
 * <p/>
 * <br/><i>Created at 2/16/14 2:03 AM, user: mishalov</i>
 *
 * @author Michael Mishalov
 * @since Android SDK 4.1, JDK 1.7
 */
public class HeadsetActionBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (Intent.ACTION_HEADSET_PLUG.equals(intent.getAction())) {
            int state = intent.getIntExtra("state", -1);
            if(AUXManagerService.isChangeAudio())
                switch (state) {
                    case 0:
                    case 1:
                        AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
                        audioManager.setMode(AudioManager.STREAM_MUSIC);
                        audioManager.setSpeakerphoneOn(true);
                        Log.d(Constants.LOGGER_CONTEXT, "Headset is " + ((state==0)? "unplugged" : "plugged"));
                        break;
                    default:
                }
        }
    }
}




Java Source Code List

com.easysoft.auxmanager.activity.EditProfileActivity.java
com.easysoft.auxmanager.activity.MainActivity.java
com.easysoft.auxmanager.activity.adapter.ApplicationAdapter.java
com.easysoft.auxmanager.activity.adapter.ApplicationModel.java
com.easysoft.auxmanager.activity.profile.ProfileSharedData.java
com.easysoft.auxmanager.listener.CallStateListener.java
com.easysoft.auxmanager.receiver.HeadsetActionBroadcastReceiver.java
com.easysoft.auxmanager.receiver.NotificationActionBroadcastReceiver.java
com.easysoft.auxmanager.service.AUXManagerService.java
com.easysoft.auxmanager.shared.ActiveProfileActivitiesExecutor.java
com.easysoft.auxmanager.shared.Constants.java
com.easysoft.auxmanager.widget.AUXManagerWidgetProvider.java