Android Open Source - RadioRake Call Receiver






From Project

Back to project page RadioRake.

License

The source code is released under:

GNU General Public License

If you think the Android project RadioRake 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.asp.radiorake;
/*from w ww  . ja v  a 2s  .  c  o  m*/
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import com.aspillai.R;

public class CallReceiver extends BroadcastReceiver {

    private static final String TAG = "com.asp.radiorake.CallReceiver";
    private Context appContext;

    public void onReceive(Context context, Intent intent) {
        RecordioPhoneStateListener recordioPhoneStateListener = new RecordioPhoneStateListener();
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        telephonyManager.listen(recordioPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
        appContext = context;
    }

    private class RecordioPhoneStateListener extends PhoneStateListener {
        Intent intent;

        @Override
        public void onCallStateChanged(int state, String incomingNumber) {

            RadioApplication radioApplication = (RadioApplication) appContext.getApplicationContext();
            MediaPlayer mediaPlayer = radioApplication.getMediaPlayer();

            if (mediaPlayer != null) {
                switch (state) {
                    case TelephonyManager.CALL_STATE_RINGING:
                        // pause
                        if (mediaPlayer.isPlaying()) {
                            Log.d(TAG, "Phone ringing, need to pause playback");
                            intent = createPlayingIntent(RadioApplication.PausePlaying);
                            PlayerService.sendWakefulWork(appContext, intent);
                        }
                        break;
                    case TelephonyManager.CALL_STATE_OFFHOOK:
                        // pause
                        if (mediaPlayer.isPlaying()) {
                            Log.d(TAG, "Phone offhook, need to pause playback");
                            intent = createPlayingIntent(RadioApplication.PausePlaying);
                            PlayerService.sendWakefulWork(appContext, intent);
                        }
                        break;
                    case TelephonyManager.CALL_STATE_IDLE:
                        // resume
                        Log.d(TAG, "Phone now idle, resuming playing");
                        intent = createPlayingIntent(RadioApplication.ResumePlaying);
                        PlayerService.sendWakefulWork(appContext, intent);
                        break;
                }
            }
        }
    }

    private Intent createPlayingIntent(int operation) {
        Intent intent = new Intent("com.statichiss.recordio.PlayerService");
        intent.putExtra(appContext.getString(R.string.player_service_operation_key), operation);
        return intent;
    }
}




Java Source Code List

com.asp.radiorake.AddNewScheduledRecordingActivity.java
com.asp.radiorake.AlarmHelper.java
com.asp.radiorake.CallReceiver.java
com.asp.radiorake.ConfirmDetailsActivity.java
com.asp.radiorake.DatabaseHelper.java
com.asp.radiorake.DatePickerFragment.java
com.asp.radiorake.LastPlayedFile.java
com.asp.radiorake.ListScheduledRecordingsActivity.java
com.asp.radiorake.NotificationHelper.java
com.asp.radiorake.PlayerService.java
com.asp.radiorake.PlayingFile.java
com.asp.radiorake.RadioActivity.java
com.asp.radiorake.RadioApplication.java
com.asp.radiorake.RadioDetails.java
com.asp.radiorake.RebootBroadcastReceiver.java
com.asp.radiorake.RecordingsActivity.java
com.asp.radiorake.RecordioBaseActivity.java
com.asp.radiorake.RemoteControlReceiver.java
com.asp.radiorake.ScheduledRecordingsCursorAdaptor.java
com.asp.radiorake.TimePickerFragment.java
com.asp.radiorake.filehandling.FileHandler.java
com.asp.radiorake.filehandling.M3uHandler.java
com.asp.radiorake.filehandling.PlsHandler.java
com.asp.radiorake.recording.RecorderService.java
com.asp.radiorake.recording.RecordingBroadcastReceiver.java
com.asp.radiorake.utils.DateUtils.java
com.asp.radiorake.utils.StringUtils.java