0

I'm having a problem to return to my app after a call as after the call is ended it sends me to the main screen instead of my app.

public class ButtonView extends FrameLayout  {
private static final String TAG = ButtonView.class.getSimpleName();
private final View mButtonView;

private Server mServer;
final Context context = getContext();

public ButtonView(Context context, AttributeSet attrs) {
    super(context, attrs);

    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    mButtonView = inflater.inflate(R.layout.input, this);
}

.
    .
    . 
    . 
    .
    .
public void call()  {
    PhoneCallListener phoneListener = new PhoneCallListener();
    TelephonyManager telephonyManager = (TelephonyManager) getContext()
            .getSystemService(Context.TELEPHONY_SERVICE);
    telephonyManager.listen(phoneListener,
            PhoneStateListener.LISTEN_CALL_STATE);

        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:048598077"));
        getContext().startActivity(callIntent); 


}


private class PhoneCallListener extends PhoneStateListener  {

    private boolean isPhoneCalling = false;
    String LOG_TAG = "LOGGING 123";

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

        if (TelephonyManager.CALL_STATE_RINGING == state) {
            // phone ringing
            Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
        }

        if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
            // active
            Log.i(LOG_TAG, "OFFHOOK");

            isPhoneCalling = true;
        }

        if (TelephonyManager.CALL_STATE_IDLE == state) {
            // run when class initial and phone call ended, 
            // need detect flag from CALL_STATE_OFFHOOK
            Log.i(LOG_TAG, "IDLE");

            if (isPhoneCalling) {

                Log.i(LOG_TAG, "restart app");

                // restart app
                Context appContext = context.getApplicationContext();
                Intent i = appContext.getPackageManager().getLaunchIntentForPackage(appContext.getPackageName());
                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                context.startActivity(i);

                isPhoneCalling = false;
            }
        }
    }
}

does someone know what the problem is? or any other way to restart the app after a call?

Lokesh Mehra
  • 545
  • 6
  • 16
igor
  • 716
  • 1
  • 9
  • 27

1 Answers1

0

if you are using emulator then kindly test your application on real device instead of emulator.and ya there is no need of PhoneStateListener and starting your application manually.just test on real device,it will start your application automatically.

Mehul Joisar
  • 15,348
  • 6
  • 48
  • 57
  • am using a real device , if i use it without the phone listener it's stais on the "call log" , but when i use the application crashes, an it bring me to the main screen. – igor Nov 20 '12 at 10:33
  • you right , i just needed to chainge in the settings "go to call log after call" – igor Nov 21 '12 at 07:57