2011-12-17 49 views
0

這是一個針對android的手機應用程序項目。我需要在通話過程中啓用後退按鈕,因此如何修復此代碼以在通話期間啓用後退按鈕?如何修復此代碼以啓用後退按鈕

public boolean onKeyDown(int keyCode, KeyEvent event) { //to enable the back button 
     if (keyCode == KeyEvent.KEYCODE_BACK) { 
      moveTaskToBack(true); 
      return true; 
     } 
     return super.onKeyDown(keyCode, event); 
    } 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     Button b = (Button) findViewById(R.id.button); 
     b.setOnClickListener(new OnClickListener() { 
      public void onClick(View v) { 
       mTelMgr.listen(mListener, PhoneStateListener.LISTEN_CALL_STATE); 
       callIntent = new Intent(Intent.ACTION_CALL, Uri 
         .parse("tel:006599")); 
       startActivity(callIntent); 

       onKeyDown(0, null);  // call the method 

      } 
     }); 
     mListener = new CallEndedListener(); 
     mTelMgr = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE); 
     onKeyDown(0, null); // recall the method 
    } 
+0

代碼有什麼問題? – 2011-12-17 20:59:46

回答

1

你的問題很混亂。當用戶撥打電話時,電話本身的通話應用程序會發出呼叫,而不是您自己的應用程序。當呼叫被放置時,後退按鈕被啓用 - 當你問「我需要在通話期間啓用後退按鈕」,所以我懷疑這不是你的問題?

如果您在撥打電話後試圖讓用戶回到您的應用程序,您可以設置廣播接收器來監聽通話結束時間,然後轉到特定的活動。也許有關整體工作流程的更多信息可能會有所幫助。