Advertisement
Guest User

Untitled

a guest
Jan 30th, 2014
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON);
  2. KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_HEADSETHOOK);
  3. i.putExtra(Intent.EXTRA_KEY_EVENT, event );
  4. context.sendOrderedBroadcast(i, null);
  5.  
  6. try {
  7. Thread.sleep(800);
  8. Process process = Runtime.getRuntime().exec(new String[]{ "su","-c","input keyevent 5"});
  9. process.waitFor();
  10.  
  11. }catch (Exception e) {
  12. e.printStackTrace();
  13. }
  14.  
  15. try {
  16. Thread.sleep(800);
  17. Process process = Runtime.getRuntime().exec(new String[]{ "su","-c","input keyevent 6"});
  18. process.waitFor();
  19.  
  20. }catch (Exception e) {
  21. e.printStackTrace();
  22. }
  23.  
  24. Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);
  25. buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN,
  26. KeyEvent.KEYCODE_CALL));
  27. context.sendOrderedBroadcast(buttonDown, "android.permission.CALL_PRIVILEGED");
  28.  
  29. // froyo and beyond trigger on buttonUp instead of buttonDown
  30. Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
  31. buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP,
  32. KeyEvent.KEYCODE_CALL));
  33. context.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
  34.  
  35. Log.d(tag, "InSecond Method Ans Call");
  36. // froyo and beyond trigger on buttonUp instead of buttonDown
  37. Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
  38. buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(
  39. KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
  40. sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
  41.  
  42. Intent headSetUnPluggedintent = new Intent(Intent.ACTION_HEADSET_PLUG);
  43. headSetUnPluggedintent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
  44. headSetUnPluggedintent.putExtra("state", 0);
  45. headSetUnPluggedintent.putExtra("name", "Headset");
  46. try {
  47. sendOrderedBroadcast(headSetUnPluggedintent, null);
  48. } catch (Exception e) {
  49. // TODO Auto-generated catch block
  50. e.printStackTrace();
  51. }
  52.  
  53. adb shell am start -n com.android.phone/.InCallScreen -a android.intent.action.ANSWER
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement