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.
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(ACTION_CRADLE_EVENT); registerReceiver(mMyHandsetObserver, intentFilter); super.onResume(); } public void onDestroy() { unregisterReceiver(mMyHandsetObserver); super.onDestroy(); } private class MyHandsetObserver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ACTION_CRADLE_EVENT)) { int state = intent.getIntExtra("EXTRA_CRADLE_EVENT_TYPE", -1); switch (state) { case EVENT_ON_HOOK: mTextView.setText("Handset: Disconnected"); break; case EVENT_OFF_HOOK: mTextView.setText("Handset: Connected"); break; } } } } In AndroidManifest.xml <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> |
Remark: If problems raising up after the update to a Android-5.1 based firmware, please be aware, that the virtual machine was changed from "dalvik" (in jellybean) to "art" (in lollipop) which is more strict in case of native code (https://developer.android.com/guide/practices/verifying-apps-art.html). Unfortunately it is not possible to switch back to dalvik in Lollipop.