Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity {
- public String secndCaller;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- //this is the method I need to be called from my AccessibilityService
- public void makeCall (){
- Intent callIntent = new Intent(Intent.ACTION_CALL);
- callIntent.setData(Uri.parse("tel:" + 123));
- callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE)
- != PackageManager.PERMISSION_GRANTED) {
- return;
- }
- startActivity(callIntent);
- }
- public class MyAccessibilityService extends AccessibilityService {
- @Override
- protected void onServiceConnected() {
- super.onServiceConnected();
- Toast.makeText(this, "Service connected", Toast.LENGTH_SHORT).show();
- AccessibilityServiceInfo info = new AccessibilityServiceInfo();
- info.eventTypes = AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED;
- info.packageNames = null;
- info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
- info.flags = AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS;
- info.notificationTimeout = 0;
- this.setServiceInfo(info);
- }
- @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
- @Override
- public void onAccessibilityEvent(AccessibilityEvent event) {
- boolean phone = event.getPackageName().toString().equals("com.android.dialer");
- if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED && phone) {
- AccessibilityNodeInfo info = event.getSource();
- if (info != null) {
- if (info.getText() != null) {
- String duration = info.getText().toString();
- String firstSecond = "00: 01";
- Rect node = new Rect();
- info.getBoundsInScreen(node);
- String node2 = node.toString();
- if (firstSecond.equals(duration) &&
- info.getContentDescription() == null &&
- node2.equals("Rect(208, 100 - 272, 132)")) {
- //Here is where I need the makeCall method to be called makeCall();
- }
- } ...
Add Comment
Please, Sign In to add comment