how do I create a listener for incoming calls?

0

I have an activity that uses the middle class MediaPlayer, and I need to keep listening in the background, but when a cell phone call comes to a halt ...

I already tried to overwrite the method onPause (), onResume (), but whenever I went to the background my player stopped, in reality what I want is that only when a call stops the player.

I appreciate your kind help. '

package com.example.especialista.reproductor;

import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    Button btn;
    MediaPlayer mp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn=(Button)findViewById(R.id.btnPlay);
        MediaPlayer mp;
        crearReproductor();
    }


    public void onClickBtnPlay(View view) {

           mp.start();
        Toast.makeText(this, "play", Toast.LENGTH_SHORT).show();

    }

    public void onClickBtnStop(View view) {

         mp.stop();
         mp.release();
         crearReproductor();
        Toast.makeText(this, "Stop", Toast.LENGTH_SHORT).show();


    }

    public  void crearReproductor(){
        mp=MediaPlayer.create(this, R.raw.piano3);

    }
}

'

    
asked by John Quintero 26.04.2018 в 22:30
source

0 answers