1

発信通話が終了したら、アクティビティに戻ろうとしています。同様の質問を見つけてコードを実装しようとしましたが、問題は oncallstatechange() メソッドであり、状態は常に 0 です。したがって、通話が行われると条件がアイドル状態の if ループにコードが直接入ってアプリに戻ってくるため、接続が切断されています。 。前もって感謝します。

//inside on create...
     callListener = new EndCallListener();
         mTM = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);


//calling on item click
public void onItemClick(AdapterView<?> av, View v, int arg2, long arg3)
    {
        // TODO Auto-generated method stub

        LinearLayout ll = (LinearLayout) ((LinearLayout) v).getChildAt(0);
        LinearLayout lc = (LinearLayout) ll.getChildAt(0);

        TextView tv = (TextView) lc.getChildAt(3);

        String st = tv.getText().toString();//contains phone number

        mTM.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);


    Intent i=new Intent(android.content.Intent.ACTION_CALL,Uri.parse("tel:"+st));
        startActivity(i);

            //finish();
         }// onitemclick

//これは、アクティビティをコールバックする場所です..

class EndCallListener extends PhoneStateListener { 


                         @Override
        state-->0        public void onCallStateChanged(int state, String incomingNumber) { 
                         super.onCallStateChanged(state, incomingNumber);

                        if(TelephonyManager.CALL_STATE_RINGING == state) {


                        }
                        if(TelephonyManager.CALL_STATE_OFFHOOK == state) {
                            //wait for phone to go offhook (probably set a boolean flag) so you know your app initiated the call.

                        }
                        if(TelephonyManager.CALL_STATE_IDLE == state) {
                            //when this state occurs, and your flag is set, restart your app


                        startActivity(new Intent(recentcalling.this,recentcalling.class));

                        }
                    }
                }
4

0 に答える 0