From 096bf989ab2efc95f820f21bcd577a5c555060ab Mon Sep 17 00:00:00 2001 From: Isaac Salazar Date: Thu, 5 Mar 2015 23:36:19 -0800 Subject: [PATCH] Initial phone call detection --- .../src/com/iktwo/musicgear/MusicGear.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/android/src/com/iktwo/musicgear/MusicGear.java b/android/src/com/iktwo/musicgear/MusicGear.java index 156382b..0309921 100644 --- a/android/src/com/iktwo/musicgear/MusicGear.java +++ b/android/src/com/iktwo/musicgear/MusicGear.java @@ -8,6 +8,9 @@ import android.net.Uri; import android.util.Log; import android.widget.Toast; +import android.os.Bundle; +import android.telephony.PhoneStateListener; +import android.telephony.TelephonyManager; import com.iktwo.musicgear.R; @@ -16,6 +19,10 @@ public class MusicGear extends org.qtproject.qt5.android.bindings.QtActivity private static final String TAG = "MusicGear"; private static DownloadManager dm; private static MusicGear m_instance; + private boolean isPausedByCall = false; + + private PhoneStateListener phoneStateListener; + private TelephonyManager telephonyManager; public MusicGear() { @@ -27,8 +34,50 @@ protected void onStart() { super.onStart(); m_instance = this; + + /* + telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); + phoneStateListener = new PhoneStateListener() { + @Override + public void onCallStateChanged(int state, String incomingNumber) { + // String stateString = "N/A"; + Log.v(TAG, "Starting CallStateChange"); + switch (state) { + case TelephonyManager.CALL_STATE_OFFHOOK: + case TelephonyManager.CALL_STATE_RINGING: + if (m_mediaPlayer != null) { + pauseMedia(); + isPausedByCall = true; + } + + break; + case TelephonyManager.CALL_STATE_IDLE: + // Phone idle. Start playing. + if (m_mediaPlayer != null) { + if (isPausedByCall) { + isPausedByCall = false; + playMedia(); + } + + } + break; + } + + } + }; + + telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); + */ } + @Override + public void onDestroy() { + if (phoneStateListener != null) { + telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE); + } + } + + public static void download(String url, String name) { Log.v(TAG, "download(" + url + ", " + name + ")");