2015-07-18 1 views
0

Je fais une démo sur appel L'application Dialer, j'ai fait avec succès les fonctionnalités entrantes et sortantes. Maintenant, mon problème est que je veux changer l'activité lorsque l'appel est rejeté ou déconnecté. J'ai essayé beaucoup de choses et j'ai aussi creusé beaucoup de liens. Quelqu'un peut-il s'il vous plaît m'aider juste comment changer l'écran lorsque l'appel est déconnecté. Mon consignataire pour call_state est comme ci-dessous:Comment changer l'écran après l'appel est rejeté ou déconnecté en android

package com.example.dialingdemo; 

import Utils.Const; 
import Utils.Pref; 
import android.app.Activity; 
import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Handler; 
import android.provider.CallLog; 
import android.telephony.TelephonyManager; 
import android.widget.Toast; 

public class MyCallReceiver extends BroadcastReceiver { 

    @Override 
    public void onReceive(final Context context, final Intent intent) { 

     if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) { 

      final String savedNumber = intent.getExtras().getString(
        "android.intent.extra.PHONE_NUMBER"); 

      new Handler().postDelayed(new Runnable() { 
       @Override 
       public void run() { 
        Intent i = new Intent(context, CallScreen.class); 
        i.putExtra("incomingNumber", savedNumber); 
        i.putExtras(intent); 
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
        i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 
        i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

        context.startActivity(i); 

        Toast.makeText(context, "OUTGOING CAL to : " + savedNumber, 
          Toast.LENGTH_LONG).show(); 
       } 
      }, 1000); 
     } 

     else if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
       TelephonyManager.EXTRA_STATE_RINGING)) { 

      final String incomingNumber = intent 
        .getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); 
      Toast.makeText(context, "Call from:" + incomingNumber, 
        Toast.LENGTH_LONG).show(); 

      new Handler().postDelayed(new Runnable() { 

       public void run() { 
        Intent i = new Intent(context, IncomingCall.class); 
        i.putExtra("incomingNumber", incomingNumber); 
        i.putExtras(intent); 
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
        i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 
        i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

        context.startActivity(i); 

       } 
      }, 1000); 

     } else if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
       TelephonyManager.EXTRA_STATE_IDLE) 
       || intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
         TelephonyManager.EXTRA_STATE_OFFHOOK)) { 

      // This code will execute when the call is disconnected 
      if (Const.call_state.equals("1")) { 

       new Handler().postDelayed(new Runnable() { 

        public void run() { 
         Intent i = new Intent(context, CallScreen.class); 

         i.putExtras(intent); 
         i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
         i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 
         i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 
         i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

         context.startActivity(i); 

        } 
       }, 1000); 
      } else if (Const.call_state.equals("2")) { 

       new Handler().postDelayed(new Runnable() { 

        public void run() { 
         Intent i = new Intent(context, CallScreen.class); 

         i.putExtras(intent); 
         i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
         i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 
         i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 
         i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

         context.startActivity(i); 

        } 
       }, 1000); 

      } 

     } 

    } 

} 
+0

donc, ce problème que vous rencontrez? –

Répondre

0

Utilisez TelephonyManager.EXTRA_STATE pour détecter l'appel sonne, décrochez ou droped

String callState= receiverIntent.getStringExtra(TelephonyManager.EXTRA_STATE); 

if (callState.equals(TelephonyManager.EXTRA_STATE_IDLE)) { 
      //call is disconnected or rejected 
}