Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In order to use the off/on hook events of the handset for 3rd party Applications, please check out codes below:

Maxwell Phone app is using com.maxwell.action.CMBS.CRADLE.EVENT for on/off hook events.

Code Block
private static final String ACTION_CRADLE_EVENT = "com.maxwell.action.CMBS.CRADLE.EVENT"; 
private static final int EVENT_OFF_HOOK = 1; 
private static final int EVENT_ON_HOOK = 2;

public void onResume() {
     IntentFilter intentFilter = new IntentFilter(Intent.ACTION_HEADSETCRADLE_PLUGEVENT);
     registerReceiver(mMyHeadsetObservermMyHandsetObserver, intentFilter);
     super.onResume(); 
}   


public void onDestroy() {
     unregisterReceiver(mMyHeadsetObservermMyHandsetObserver);
     super.onDestroy(); 
}   


private class MyHeadsetObserverMyHandsetObserver extends BroadcastReceiver {
     @Override
     public void onReceive(Context context, Intent intent) {
         if (intent.getAction().equals(Intent.ACTION_HEADSETCRADLE_PLUGEVENT)) {
             int state = intent.getIntExtra("stateEXTRA_CRADLE_EVENT_TYPE", -1);
             switch (state) {
                 case 0EVENT_ON_HOOK:
                     mTextView.setText("Handset / Headset: Disconnected");
                     break;
                 case 1EVENT_OFF_HOOK:
                     mTextView.setText("Handset / Headset: Connected");
                     break;
             }
         }
     }
}




In AndroidManifest.xml
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

...