Android挂断、接听电话(4)
来源:未知 责任编辑:责任编辑 发表时间:2013-12-01 14:14 点击:次
package lab.sodino.phonecall; import java.lang.reflect.Method; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.telephony.TelephonyManager; import android.view.View; import android.widget.Button; import com.android.internal.telephony.ITelephony; /** *@author Sodino Email:sodinoopen@hotmail<br/> *@version 2011-2-6 下午08:33:25 */ public class ShowAct extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setWindowAnimations(0); setContentView(R.layout.show); Button btnRefuse = (Button) findViewById(R.id.btnRefuse); btnRefuse.setOnClickListener(new Button.OnClickListener() { public void onClick(View view) { endCall(); } }); Button btnReceiver = (Button) findViewById(R.id.btnRefuse); btnReceiver.setOnClickListener(new Button.OnClickListener() { public void onClick(View view) { answerCall(); } }); } private void answerCall() { TelephonyManager telMag = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); Class<TelephonyManager> c = TelephonyManager.class; Method mthEndCall = null; try { mthEndCall = c.getDeclaredMethod("getITelephony", (Class[]) null); mthEndCall.setAccessible(true); ITelephony iTel = (ITelephony) mthEndCall.invoke(telMag, (Object[]) null); iTel.answerRingingCall(); LogOut.out(this, iTel.toString()); } catch (Exception e) { e.printStackTrace(); } LogOut.out(this, "answer call"); } private void endCall() { TelephonyManager telMag = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); Class<TelephonyManager> c = TelephonyManager.class; Method mthEndCall = null; try { mthEndCall = c.getDeclaredMethod("getITelephony", (Class[]) null); mthEndCall.setAccessible(true); ITelephony iTel = (ITelephony) mthEndCall.invoke(telMag, (Object[]) null); iTel.endCall(); LogOut.out(this, iTel.toString()); } catch (Exception e) { e.printStackTrace(); } LogOut.out(this, "endCall test"); } public void onStart() { super.onStart(); // 1.经测试,貌似无法杀掉phone程序 // ActivityManager actMag = (ActivityManager) // getSystemService(Context.ACTIVITY_SERVICE); // actMag.killBackgroundProcesses("com.android.phone"); // 2.来个恶搞:直接回桌面去,heihei... // Intent tmpI = new Intent(Intent.ACTION_MAIN); // tmpI.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // tmpI.addCategory(Intent.CATEGORY_HOME); // startActivity(tmpI); // LogOut.out(this, "killBgPro&&startHome"); } public void onPause() { super.onPause(); finish(); } }
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>