Android hangs up and receives calls

Source: Internet
Author: User

 

A simple example

Reference: using the AIDL and reflection mechanisms, you can use hidden APIs to stop a call.

 

Personally, Dalvik VM is actually spoofed across processes of the same name. You can think of the extended functions of Dalvik VM, and we will be pleasantly surprised !!!

The following is the source code for personal backup and reference only.

Package lab. sodino. phonecall; import android. app. activity; import android. OS. bundle; public class PhoneCall extends Activity {/** Called when the activity is first created. * // @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main );}}

 

 

Package lab. sodino. phonecall; import android. app. service; import android. content. broadcastReceiver; import android. content. context; import android. content. intent; import android. telephony. telephonyManager; import android. widget. toast;/*** @ author Sodino Email: sodinoopen @ hotmail <br/> * @ version 2011-2-6 10:38:55 */public class PhoneListener extends BroadcastReceiver {public void onReceive (Context context, intent intent) {String action = intent. getAction (); LogOut. out (this, "ord:" + isOrderedBroadcast () + "act:" + action); Toast toast = Toast. makeText (context, "", Toast. LENGTH_SHORT); if (action. equals ("android. intent. action. NEW_OUTGOING_CALL ") {toast. setText ("Outgoing");} else {toast. setText ("InComing"); TelephonyManager tm = (TelephonyManager) context. getSystemService (Service. TELEPHONY_SERVICE); boolean incomingFlag = false; String incoming_number = ""; switch (tm. getCallState () {case TelephonyManager. CALL_STATE_RINGING: incomingFlag = true; // identifies the current incoming call incoming_number = intent. getStringExtra ("incoming_number"); LogOut. out (this, "RINGING:" + incoming_number); try {Thread. sleep (3000);} catch (InterruptedException e) {e. printStackTrace ();} Intent tmpI = new Intent (context, ShowAct. class); tmpI. setFlags (Intent. FLAG_ACTIVITY_NEW_TASK); context. startActivity (tmpI); break; case TelephonyManager. CALL_STATE_OFFHOOK: if (incomingFlag) {LogOut. out (this, "incoming ACCEPT:" + incoming_number);} break; case TelephonyManager. CALL_STATE_IDLE: if (incomingFlag) {LogOut. out (this, "incoming IDLE") ;}break ;}} toast. show ();}}

 

 

 

 

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. after testing, it seems that the phone program // ActivityManager actMag = (ActivityManager) // getSystemService (Context. ACTIVITY_SERVICE); // actMag. killBackgroundProcesses ("com. android. phone "); // 2. come on! Go back to the desktop directly, 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 ();}}

 

 

 

Package com. android. internal. telephony; interface ITelephony {boolean endCall (); void answerRingingCall ();}

 

 

 

 

 

 

 

<? Xml version = "1.0" encoding = "UTF-8"?> <Manifest xmlns: android = "http://schemas.android.com/apk/res/android" package = "lab. sodino. phonecall "android: versionCode =" 1 "android: versionName =" 1.0 "> <application android: icon =" @ drawable/icon "android: label = "@ string/app_name"> <activity android: name = ". phoneCall "android: label =" @ string/app_name "> <intent-filter> <action android: name =" android. intent. action. MAIN "/> <category android: name =" android. intent. category. LAUNCHER "/> </intent-filter> </activity> <activity android: name = ". showAct "android: launchMode =" singleInstance "> </activity> <Cycler android: name = ". phoneListener "> <intent-filter android: priority ="-1000 "> <action android: name =" android. intent. action. PHONE_STATE "> </action> <category android: name =" android. intent. category. DEFAULT "> </category> </intent-filter> <action android: name =" android. intent. action. NEW_OUTGOING_CALL "> </action> <category android: name =" android. intent. category. DEFAULT "> </category> </intent-filter> </Cycler> </application> <uses-sdk android: minSdkVersion =" 3 "/> <uses-permission android: name = "android. permission. MODIFY_PHONE_STATE "> </uses-permission> <uses-permission android: name =" android. permission. CALL_PHONE "> </uses-permission> <uses-permission android: name =" android. permission. READ_PHONE_STATE "> </uses-permission> </manifest>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.