Guest User

Untitled

a guest
Dec 13th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2.  
  3. public String secndCaller;
  4. @Override
  5. protected void onCreate(Bundle savedInstanceState) {
  6. super.onCreate(savedInstanceState);
  7. setContentView(R.layout.activity_main);
  8.  
  9.  
  10. }
  11.  
  12. //this is the method I need to be called from my AccessibilityService
  13.  
  14. public void makeCall (){
  15. Intent callIntent = new Intent(Intent.ACTION_CALL);
  16. callIntent.setData(Uri.parse("tel:" + 123));
  17. callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  18.  
  19. if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE)
  20. != PackageManager.PERMISSION_GRANTED) {
  21. return;
  22. }
  23. startActivity(callIntent);
  24. }
  25.  
  26. public class MyAccessibilityService extends AccessibilityService {
  27.  
  28.  
  29. @Override
  30. protected void onServiceConnected() {
  31. super.onServiceConnected();
  32.  
  33. Toast.makeText(this, "Service connected", Toast.LENGTH_SHORT).show();
  34. AccessibilityServiceInfo info = new AccessibilityServiceInfo();
  35.  
  36. info.eventTypes = AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED;
  37. info.packageNames = null;
  38. info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
  39. info.flags = AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS;
  40. info.notificationTimeout = 0;
  41. this.setServiceInfo(info);
  42. }
  43.  
  44. @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
  45. @Override
  46. public void onAccessibilityEvent(AccessibilityEvent event) {
  47.  
  48. boolean phone = event.getPackageName().toString().equals("com.android.dialer");
  49.  
  50. if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED && phone) {
  51.  
  52.  
  53. AccessibilityNodeInfo info = event.getSource();
  54. if (info != null) {
  55.  
  56. if (info.getText() != null) {
  57. String duration = info.getText().toString();
  58. String firstSecond = "00: 01";
  59. Rect node = new Rect();
  60. info.getBoundsInScreen(node);
  61. String node2 = node.toString();
  62.  
  63. if (firstSecond.equals(duration) &&
  64. info.getContentDescription() == null &&
  65. node2.equals("Rect(208, 100 - 272, 132)")) {
  66.  
  67.  
  68.  
  69. //Here is where I need the makeCall method to be called makeCall();
  70.  
  71.  
  72.  
  73. }
  74. } ...
Add Comment
Please, Sign In to add comment