2013-03-29 48 views
0

我在这里尝试打电话,它的工作原理,但问题是当我完成通话时,我没有看到我的视图。 。而当我在我的手机按钮返回,又回到我的活动,我想显示点击...谢谢:)在通话结束后Automatiquelly恢复应用程序

@Override 
public void onClick(View arg0) { 

    if (arg0 == btn_ajout) { 
     Intent i=new Intent(Docteur_gestion.this, AjoutDocActivity.class); 
     startActivity(i); 
    } 

    if(arg0 == btn_appel) { 
     Intent callIntent = new Intent(Intent.ACTION_CALL); 
     callIntent.setData(Uri.parse("tel:"+global_txt_tel_doc)); 
     startActivity(callIntent);  
    } 
} 
+0

你想要的东西.. – Unknown

+0

您的格式是相当糟糕的。请确保您至少大写正确,并且您的代码示例已正确缩进。这就是为什么在底部有动态预览。 –

+0

@CobraAjgar当我挂断电话(解除后)我想再次看到活动没有菜单调用(通话记录)对不起格式不好... –

回答

2

你需要实现一个phoneStateListener如下:

public class MainActivity extends Activity { 

    final Context context = this; 
    private Button button; 

    public void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     button = (Button) findViewById(R.id.buttonCall); 

     // add PhoneStateListener 
     PhoneCallListener phoneListener = new PhoneCallListener(); 
     TelephonyManager telephonyManager = (TelephonyManager) this 
      .getSystemService(Context.TELEPHONY_SERVICE); 
     telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE); 

     // add button listener 
     button.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 

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

      } 

     }); 

    } 

    //monitor phone call activities 
    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 
        Intent i = getBaseContext().getPackageManager() 
         .getLaunchIntentForPackage(
          getBaseContext().getPackageName()); 
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
        startActivity(i); 

        isPhoneCalling = false; 
       } 

      } 
     } 
    } 

} 

清单中需要两个权限

<uses-permission android:name="android.permission.READ_PHONE_STATE" /> 

<uses-permission android:name="android.permission.CALL_PHONE" /> 

我发现这个解决方案在此link

相关问题