android.content.Intent#ACTION_HEADSET_PLUG源码实例Demo

下面列出了android.content.Intent#ACTION_HEADSET_PLUG 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: FamilyChat   文件: HeadSetReceiver.java
@Override
public void onReceive(Context context, Intent intent)
{
    String action = intent.getAction();
    switch (action)
    {
        //插入和拔出耳机会触发此广播
        case Intent.ACTION_HEADSET_PLUG:
            int state = intent.getIntExtra("state", 0);
            if (state == 1)
            {
                //耳机插入
                if (mListener != null)
                    mListener.onHeadSetStateChanged(true);
            } else if (state == 0)
            {
                //耳机拔出
                if (mListener != null)
                    mListener.onHeadSetStateChanged(false);
            }
            break;
        default:
            break;
    }
}
 
源代码2 项目: mollyim-android   文件: WebRtcCallService.java
private void registerWiredHeadsetStateReceiver() {
  wiredHeadsetStateReceiver = new WiredHeadsetStateReceiver();

  String action;

  if (Build.VERSION.SDK_INT >= 21) {
    action = AudioManager.ACTION_HEADSET_PLUG;
  } else {
    action = Intent.ACTION_HEADSET_PLUG;
  }

  registerReceiver(wiredHeadsetStateReceiver, new IntentFilter(action));
}
 
源代码3 项目: PHONK   文件: PMedia.java
public void onHeadsetConnection(ReturnInterface callbackfn) {
    headsetCallbackfn = callbackfn;

    IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
    headsetPluggedReceiver = new HeadSetReceiver();
    getContext().registerReceiver(headsetPluggedReceiver, filter);
}
 
源代码4 项目: iGap-Android   文件: ActivityCall.java
@Override
protected void onResume() {
    super.onResume();

    if (callTYpe == ProtoSignalingOffer.SignalingOffer.Type.VIDEO_CALLING) {
        G.onVideoCallFrame = ActivityCall.this;
        WebRTC.getInstance().startVideoCapture();
    }

    mSensorManager.registerListener(sensorEventListener, mProximity, SensorManager.SENSOR_DELAY_NORMAL);
    IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
    registerReceiver(headsetPluginReciver, filter);
}
 
public CustomTwilioVideoView(ThemedReactContext context) {
    super(context);
    this.themedReactContext = context;
    this.eventEmitter = themedReactContext.getJSModule(RCTEventEmitter.class);

    // add lifecycle for onResume and on onPause
    themedReactContext.addLifecycleEventListener(this);

    /*
     * Enable changing the volume using the up/down keys during a conversation
     */
    if (themedReactContext.getCurrentActivity() != null) {
        themedReactContext.getCurrentActivity().setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
    }
    /*
     * Needed for setting/abandoning audio focus during call
     */
    audioManager = (AudioManager) themedReactContext.getSystemService(Context.AUDIO_SERVICE);
    myNoisyAudioStreamReceiver = new BecomingNoisyReceiver();
    intentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);

    // Create the local data track
   // localDataTrack = LocalDataTrack.create(this);
   localDataTrack = LocalDataTrack.create(getContext());

   // Start the thread where data messages are received
    dataTrackMessageThread.start();
    dataTrackMessageThreadHandler = new Handler(dataTrackMessageThread.getLooper());

}
 
源代码6 项目: webTube   文件: MainActivity.java
@Override
public void onResume() {
    super.onResume();
    backgroundPlayHelper.hideBackgroundPlaybackNotification();

    IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
    registerReceiver(headSetReceiver, filter);
}
 
源代码7 项目: webTube   文件: MainActivity.java
@Override
public void onResume() {
    super.onResume();
    backgroundPlayHelper.hideBackgroundPlaybackNotification();

    IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
    registerReceiver(headSetReceiver, filter);
}
 
源代码8 项目: sealrtc-android   文件: AppRTCAudioManager.java
/**
 * Registers receiver for the broadcasted intent when a wired headset is plugged in or
 * unplugged. The received intent will have an extra 'state' value where 0 means unplugged, and
 * 1 means plugged.
 */
private void registerForWiredHeadsetIntentBroadcast() {
    IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);

    /** Receiver which handles changes in wired headset availability. */
    wiredHeadsetReceiver =
            new BroadcastReceiver() {
                private static final int STATE_UNPLUGGED = 0;
                private static final int STATE_PLUGGED = 1;
                private static final int HAS_NO_MIC = 0;
                private static final int HAS_MIC = 1;

                @Override
                public void onReceive(Context context, Intent intent) {
                    if (BluetoothUtil.hasBluetoothA2dpConnected()) return;
                    int state = intent.getIntExtra("state", STATE_UNPLUGGED);
                    int microphone = intent.getIntExtra("microphone", HAS_NO_MIC);
                    String name = intent.getStringExtra("name");
                    Log.d(
                            TAG,
                            "BroadcastReceiver.onReceive"
                                    + AppRTCUtils.getThreadInfo()
                                    + ": "
                                    + "a="
                                    + intent.getAction()
                                    + ", s="
                                    + (state == STATE_UNPLUGGED ? "unplugged" : "plugged")
                                    + ", m="
                                    + (microphone == HAS_MIC ? "mic" : "no mic")
                                    + ", n="
                                    + name
                                    + ", sb="
                                    + isInitialStickyBroadcast());

                    boolean hasWiredHeadset = (state == STATE_PLUGGED) ? true : false;
                    switch (state) {
                        case STATE_UNPLUGGED:
                            updateAudioDeviceState(hasWiredHeadset);
                            audioManager.setSpeakerphoneOn(isCurrentSpeakerOn);
                            break;
                        case STATE_PLUGGED:
                            if (selectedAudioDevice != AudioDevice.WIRED_HEADSET) {
                                updateAudioDeviceState(hasWiredHeadset);
                            }
                            break;
                        default:
                            Log.e(TAG, "Invalid state");
                            break;
                    }
                }
            };
    if (apprtcContext != null) {
        apprtcContext.registerReceiver(wiredHeadsetReceiver, filter);
    }
}
 
源代码9 项目: IdealMedia   文件: PlayerService.java
@Override
public void onCreate() {
	super.onCreate();

	// initialize default output device
	if (!BASS.BASS_Init(-1, 44100, 0)) {
		return;
	}

	// look for plugins
	plugins = "";
       String path = getApplicationInfo().nativeLibraryDir;
	String[] list = new File(path).list();
	for (String s: list) {
		int plug = BASS.BASS_PluginLoad(path+"/"+s, 0);
		if (plug != 0) { // plugin loaded...
			plugins += s + "\n"; // add it to the list
		}
	}
	if (plugins.equals(""))
           plugins = "no plugins - visit the BASS webpage to get some\n";
	if(playerInterface != null) {
		playerInterface.onPluginsLoaded(plugins);
	}

       BASS.BASS_SetConfig(BASS.BASS_CONFIG_BUFFER, 1000);
       Log.w("BASS.BASS_CONFIG_BUFFER", "" + BASS.BASS_GetConfig(BASS.BASS_CONFIG_BUFFER));

	// Pending Intend
	Intent intent = new Intent(this, NavigationActivity.class);
	intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
	pendIntent = PendingIntent.getActivity(this, 0, intent, 0);

       //tracklist
       loadTracks();
       loadEqualizerValues();

       tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
       tm.listen(telephone, PhoneStateListener.LISTEN_CALL_STATE);

       myBroadcastReceiver = new ServiceBroadcastReceiver();
       IntentFilter intentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
       intentFilter.addAction("android.media.VOLUME_CHANGED_ACTION");
       intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED);
       registerReceiver(myBroadcastReceiver, intentFilter);

       ComponentName rcvMedia = new ComponentName(getPackageName(), MediaControlReceiver.class.getName());
       mAudioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
       mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
       mAudioManager.registerMediaButtonEventReceiver(rcvMedia);

       // Use the remote control APIs (if available) to set the playback state
       if (Build.VERSION.SDK_INT >= 14 && remoteControlClient == null) {
           registerRemoteControl(rcvMedia);
       }
}
 
源代码10 项目: Rey-MusicPlayer   文件: MusicService.java
public void registerHeadsetPlugReceiver() {
    IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
    mHeadsetPlugReceiver = new HeadsetPlugBroadcastReceiver();
    mService.registerReceiver(mHeadsetPlugReceiver, filter);
}
 
源代码11 项目: Status   文件: HeadphoneIconData.java
@Override
public IntentFilter getIntentFilter() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        return new IntentFilter(AudioManager.ACTION_HEADSET_PLUG);
    else return new IntentFilter(Intent.ACTION_HEADSET_PLUG);
}
 
源代码12 项目: Yahala-Messenger   文件: AppRTCAudioManager.java
/**
 * Registers receiver for the broadcasted intent when a wired headset is
 * plugged in or unplugged. The received intent will have an extra
 * 'state' value where 0 means unplugged, and 1 means plugged.
 */
private void registerForWiredHeadsetIntentBroadcast() {
    IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);

    /** Receiver which handles changes in wired headset availability. */
    wiredHeadsetReceiver = new BroadcastReceiver() {
        private static final int STATE_UNPLUGGED = 0;
        private static final int STATE_PLUGGED = 1;
        private static final int HAS_NO_MIC = 0;
        private static final int HAS_MIC = 1;

        @Override
        public void onReceive(Context context, Intent intent) {
            int state = intent.getIntExtra("state", STATE_UNPLUGGED);
            int microphone = intent.getIntExtra("microphone", HAS_NO_MIC);
            String name = intent.getStringExtra("name");
            Log.d(TAG, "BroadcastReceiver.onReceive" + AppRTCUtils.getThreadInfo()
                    + ": "
                    + "a=" + intent.getAction()
                    + ", s=" + (state == STATE_UNPLUGGED ? "unplugged" : "plugged")
                    + ", m=" + (microphone == HAS_MIC ? "mic" : "no mic")
                    + ", n=" + name
                    + ", sb=" + isInitialStickyBroadcast());

            boolean hasWiredHeadset = (state == STATE_PLUGGED) ? true : false;
            switch (state) {
                case STATE_UNPLUGGED:
                    updateAudioDeviceState(hasWiredHeadset);
                    break;
                case STATE_PLUGGED:
                    if (selectedAudioDevice != AudioDevice.WIRED_HEADSET) {
                        updateAudioDeviceState(hasWiredHeadset);
                    }
                    break;
                default:
                    Log.e(TAG, "Invalid state");
                    break;
            }
        }
    };

    apprtcContext.registerReceiver(wiredHeadsetReceiver, filter);
}
 
源代码13 项目: 365browser   文件: AudioManagerAndroid.java
/**
 * Registers receiver for the broadcasted intent when a wired headset is
 * plugged in or unplugged. The received intent will have an extra
 * 'state' value where 0 means unplugged, and 1 means plugged.
 */
private void registerForWiredHeadsetIntentBroadcast() {
    IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);

    /** Receiver which handles changes in wired headset availability. */
    mWiredHeadsetReceiver = new BroadcastReceiver() {
        private static final int STATE_UNPLUGGED = 0;
        private static final int STATE_PLUGGED = 1;
        private static final int HAS_NO_MIC = 0;
        private static final int HAS_MIC = 1;

        @Override
        public void onReceive(Context context, Intent intent) {
            int state = intent.getIntExtra("state", STATE_UNPLUGGED);
            if (DEBUG) {
                int microphone = intent.getIntExtra("microphone", HAS_NO_MIC);
                String name = intent.getStringExtra("name");
                logd("BroadcastReceiver.onReceive: a=" + intent.getAction()
                        + ", s=" + state
                        + ", m=" + microphone
                        + ", n=" + name
                        + ", sb=" + isInitialStickyBroadcast());
            }
            switch (state) {
                case STATE_UNPLUGGED:
                    synchronized (mLock) {
                        // Wired headset and earpiece and USB audio are mutually exclusive.
                        mAudioDevices[DEVICE_WIRED_HEADSET] = false;
                        if (hasUsbAudio()) {
                            mAudioDevices[DEVICE_USB_AUDIO] = true;
                            mAudioDevices[DEVICE_EARPIECE] = false;
                        } else if (hasEarpiece()) {
                            mAudioDevices[DEVICE_EARPIECE] = true;
                            mAudioDevices[DEVICE_USB_AUDIO] = false;
                        }
                    }
                    break;
                case STATE_PLUGGED:
                    synchronized (mLock) {
                        // Wired headset and earpiece and USB audio are mutually exclusive.
                        mAudioDevices[DEVICE_WIRED_HEADSET] = true;
                        mAudioDevices[DEVICE_EARPIECE] = false;
                        mAudioDevices[DEVICE_USB_AUDIO] = false;
                    }
                    break;
                default:
                    loge("Invalid state");
                    break;
            }

            // Update the existing device selection, but only if a specific
            // device has already been selected explicitly.
            if (deviceHasBeenRequested()) {
                updateDeviceActivation();
            } else if (DEBUG) {
                reportUpdate();
            }
        }
    };

    // Note: the intent we register for here is sticky, so it'll tell us
    // immediately what the last action was (plugged or unplugged).
    // It will enable us to set the speakerphone correctly.
    ContextUtils.getApplicationContext().registerReceiver(mWiredHeadsetReceiver, filter);
}
 
源代码14 项目: voip_android   文件: VOIPVideoActivity.java
@Override
public void onResume() {
    IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
    registerReceiver(headsetReceiver, filter);
    super.onResume();
}
 
源代码15 项目: restcomm-android-sdk   文件: AppRTCAudioManager.java
/**
 * Registers receiver for the broadcasted intent when a wired headset is
 * plugged in or unplugged. The received intent will have an extra
 * 'state' value where 0 means unplugged, and 1 means plugged.
 */
private void registerForWiredHeadsetIntentBroadcast()
{
   IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);

   /** Receiver which handles changes in wired headset availability. */
   wiredHeadsetReceiver = new BroadcastReceiver() {
      private static final int STATE_UNPLUGGED = 0;
      private static final int STATE_PLUGGED = 1;
      private static final int HAS_NO_MIC = 0;
      private static final int HAS_MIC = 1;

      @Override
      public void onReceive(Context context, Intent intent)
      {
         int state = intent.getIntExtra("state", STATE_UNPLUGGED);
         int microphone = intent.getIntExtra("microphone", HAS_NO_MIC);
         String name = intent.getStringExtra("name");
         RCLogger.d(TAG, "BroadcastReceiver.onReceive" + AppRTCUtils.getThreadInfo()
               + ": "
               + "a=" + intent.getAction()
               + ", s=" + (state == STATE_UNPLUGGED ? "unplugged" : "plugged")
               + ", m=" + (microphone == HAS_MIC ? "mic" : "no mic")
               + ", n=" + name
               + ", sb=" + isInitialStickyBroadcast());

         switch (state) {
            case STATE_UNPLUGGED:
               updateAudioDeviceState(false);
               break;
            case STATE_PLUGGED:
               updateAudioDeviceState(true);
               break;
            default:
               RCLogger.e(TAG, "Invalid state");
               break;
         }
      }
   };

   apprtcContext.registerReceiver(wiredHeadsetReceiver, filter);
}
 
源代码16 项目: freemp   文件: ServicePlayer.java
@Override
public void onCreate() {
    super.onCreate();

    // initialize default output device
    if (!BASS.BASS_Init(-1, 44100, 0)) {
        return;
    }

    // look for plugins
    plugins = "";
    String path = getApplicationInfo().nativeLibraryDir;
    String[] list = new File(path).list();
    for (String s : list) {
        int plug = BASS.BASS_PluginLoad(path + "/" + s, 0);
        if (plug != 0) { // plugin loaded...
            plugins += s + "\n"; // add it to the list
        }
    }
    if (plugins.equals("")) plugins = "no plugins - visit the BASS webpage to get some\n";
    if (activity != null) {
        activity.onPluginsLoaded(plugins);
    }
    BASS.BASS_SetConfig(BASS.BASS_CONFIG_BUFFER, 1000);
    Log.w("BASS.BASS_CONFIG_BUFFER", "" + BASS.BASS_GetConfig(BASS.BASS_CONFIG_BUFFER));
    //screen
    screenHeight = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getInt("screenHeight", 1000);
    screenWidth = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getInt("screenWidth", 800);

    // Pending Intend
    Intent intent = new Intent(this, ActPlayer.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    pendIntent = PendingIntent.getActivity(this, 0, intent, 0);

    //tracklist
    updateTrackList();

    tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    tm.listen(telephone, PhoneStateListener.LISTEN_CALL_STATE);
    myBroadcastReceiver = new MyBroadcastReceiver();
    IntentFilter intentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
    intentFilter.addAction("android.media.VOLUME_CHANGED_ACTION");
    intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED);
    registerReceiver(myBroadcastReceiver, intentFilter);


    mAudioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
    mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN);
    ComponentName rcvMedia = new ComponentName(getPackageName(), RcvMediaControl.class.getName());
    mAudioManager.registerMediaButtonEventReceiver(rcvMedia);

    // Use the remote control APIs (if available) to set the playback state
    if (android.os.Build.VERSION.SDK_INT >= 14 && remoteControlClient == null) {
        registerRemoteControl(rcvMedia);
    }
}
 
源代码17 项目: webrtc-app-mono   文件: WebRTCDemo.java
@Override
public void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "onCreate");

    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    populateCameraOrientations();

    setContentView(R.layout.tabhost);

    IntentFilter receiverFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);

    receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().compareTo(Intent.ACTION_HEADSET_PLUG)
                    == 0) {
                int state = intent.getIntExtra("state", 0);
                Log.v(TAG, "Intent.ACTION_HEADSET_PLUG state: " + state +
                     " microphone: " + intent.getIntExtra("microphone", 0));
                if (voERunning) {
                    routeAudio(state == 0 && cbEnableSpeaker.isChecked());
                }
            }
        }
    };
    registerReceiver(receiver, receiverFilter);

    mTabHost = getTabHost();

    // Main tab
    mTabSpecVideo = mTabHost.newTabSpec("tab_video");
    mTabSpecVideo.setIndicator("Main");
    mTabSpecVideo.setContent(R.id.tab_video);
    mTabHost.addTab(mTabSpecVideo);

    // Shared config tab
    mTabHost = getTabHost();
    mTabSpecConfig = mTabHost.newTabSpec("tab_config");
    mTabSpecConfig.setIndicator("Settings");
    mTabSpecConfig.setContent(R.id.tab_config);
    mTabHost.addTab(mTabSpecConfig);

    TabSpec mTabv;
    mTabv = mTabHost.newTabSpec("tab_vconfig");
    mTabv.setIndicator("Video");
    mTabv.setContent(R.id.tab_vconfig);
    mTabHost.addTab(mTabv);
    TabSpec mTaba;
    mTaba = mTabHost.newTabSpec("tab_aconfig");
    mTaba.setIndicator("Audio");
    mTaba.setContent(R.id.tab_aconfig);
    mTabHost.addTab(mTaba);

    int childCount = mTabHost.getTabWidget().getChildCount();
    for (int i = 0; i < childCount; i++) {
        mTabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 50;
    }
    orientationListener =
            new OrientationEventListener(this, SensorManager.SENSOR_DELAY_UI) {
                public void onOrientationChanged (int orientation) {
                    if (orientation != ORIENTATION_UNKNOWN) {
                        currentDeviceOrientation = orientation;
                        compensateCameraRotation();
                    }
                }
            };
    orientationListener.enable ();

    // Create a folder named webrtc in /scard for debugging
    webrtcDebugDir = Environment.getExternalStorageDirectory().toString() +
            webrtcName;
    File webrtcDir = new File(webrtcDebugDir);
    if (!webrtcDir.exists() && webrtcDir.mkdir() == false) {
        Log.v(TAG, "Failed to create " + webrtcDebugDir);
    } else if (!webrtcDir.isDirectory()) {
        Log.v(TAG, webrtcDebugDir + " exists but not a folder");
        webrtcDebugDir = null;
    }

    startMain();

    if (AUTO_CALL_RESTART_DELAY_MS > 0)
        startOrStop();
}
 
源代码18 项目: Augendiagnose   文件: HeadsetPlugReceiver.java
/**
 * Register this receiver.
 *
 * @param context The context
 * @param handler A handler for headset plug events
 */
public void register(final Context context, final HeadsetPlugHandler handler) {
	mHandler = handler;
	IntentFilter intentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
	context.registerReceiver(this, intentFilter);
}
 
 方法所在类
 同类方法