2012-05-20 66 views
0

我正在使用Intent intent = new Intent(Intent.ACTION_CALL);從我的應用程序撥打電話。如何停止一次intent.ACTION_CALL啓動?

有沒有什麼辦法在一段時間後終止通話?或者在ACTION_CALL啓動之前設置一個定時器?

我使用下面的代碼從Prasanta的博客,但由於某種原因context正在獲取下面的錯誤。有什麼建議麼?

不能得到解決

import java.lang.reflect.Method; 
import android.app.Activity; 
import android.content.Context; 
import android.os.Bundle; 
import android.os.RemoteException; 
import android.telephony.PhoneStateListener; 
import android.telephony.TelephonyManager; 
import android.util.Log; 
import android.widget.CheckBox; 
import android.widget.CompoundButton; 
import android.widget.CompoundButton.OnCheckedChangeListener; 
import android.widget.TextView; 
import android.widget.Toast; 
import com.android.internal.telephony.ITelephony; 


public class AnswerActivity extends Activity { 
    private static final String TAG = null; 
    /** Called when the activity is first created. */ 
    private ITelephony telephonyService; 
    TelephonyManager telephonyManager; 

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

    TelephonyManager tm = (TelephonyManager) context 
      .getSystemService(Context.TELEPHONY_SERVICE);{ 

    try { 
     // Java reflection to gain access to TelephonyManager's 
     // ITelephony getter 
     Log.v(TAG, "Get getTeleService..."); 
     Class c = Class.forName(tm.getClass().getName()); 
     Method m = c.getDeclaredMethod("getITelephony"); 
     m.setAccessible(true); 
     com.android.internal.telephony.ITelephony telephonyService = 
       (ITelephony) m.invoke(tm); 
    } catch (Exception e) { 
     e.printStackTrace(); 
     Log.e(TAG, 
       "FATAL ERROR: could not connect to telephony subsystem"); 
     Log.e(TAG, "Exception object: " + e); 
    } 

} 
    } 
} 
+1

看到這篇文章http://stackoverflow.com/questions/599443/android-how-to-hang-up-outgoing-call –

+0

@MoshErsan謝謝,我已閱讀該帖子,但我無法執行。 conext無法解析錯誤 – Parksie

+0

在這裏寫一些代碼看看 –

回答

1

你的問題已經被問了很多次。簡短的回答是,沒有官方的方式來做到這一點。

長回答:

仔細閱讀。尋找有人說「過去工作......」的案例。

在某人提出打開飛行模式的問題之一(當然,該應用程序需要執行此操作的權限)。這是粗糙的,但它的工作原理。作爲一個用戶,我會對一個應用程序做一些保留,但是。

+0

謝謝,我會看看。這不適用於市場或類似的應用程序。它將用於我公司的網絡測試。 – Parksie