Why are accessibility service not working to take user actions?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















@Override
public void onAccessibilityEvent(final AccessibilityEvent event) {

Date date = new Date(event.getEventTime());
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm");
String time = format.format(date);
String reqTime = "25/11/2018 04:39";
if (reqTime.equals(time)) {
Log.d("MyAccessibilityService", "onAccessibilityEvent");

if (getRootInActiveWindow() == null) {
return;
}


AccessibilityNodeInfoCompat rootInActiveWindow = AccessibilityNodeInfoCompat.wrap(getRootInActiveWindow());
//Inspect app elements if ready

//Search bar is covered with textview which need to be clicked
List<AccessibilityNodeInfoCompat> clickOnQuestionMark = rootInActiveWindow.findAccessibilityNodeInfosByViewId("com.whatsapp:id/menuitem_search");
if (clickOnQuestionMark.isEmpty() || clickOnQuestionMark == null) {
return;
}
AccessibilityNodeInfoCompat clickMark = clickOnQuestionMark.get(0);
clickMark.performAction(AccessibilityNodeInfoCompat.ACTION_CLICK);


I am using this code for simuating clicking whatsapp search button, but when I opened whatsapp window on 25-11-2018 at 4:39 nothing happened. The code was working fine when no time was alloted. But problem was that everytime whatsapp was opened the search button would get clicked. How to click on the search button only when whatsapp is opened at a specific time?










share|improve this question































    0















    @Override
    public void onAccessibilityEvent(final AccessibilityEvent event) {

    Date date = new Date(event.getEventTime());
    SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm");
    String time = format.format(date);
    String reqTime = "25/11/2018 04:39";
    if (reqTime.equals(time)) {
    Log.d("MyAccessibilityService", "onAccessibilityEvent");

    if (getRootInActiveWindow() == null) {
    return;
    }


    AccessibilityNodeInfoCompat rootInActiveWindow = AccessibilityNodeInfoCompat.wrap(getRootInActiveWindow());
    //Inspect app elements if ready

    //Search bar is covered with textview which need to be clicked
    List<AccessibilityNodeInfoCompat> clickOnQuestionMark = rootInActiveWindow.findAccessibilityNodeInfosByViewId("com.whatsapp:id/menuitem_search");
    if (clickOnQuestionMark.isEmpty() || clickOnQuestionMark == null) {
    return;
    }
    AccessibilityNodeInfoCompat clickMark = clickOnQuestionMark.get(0);
    clickMark.performAction(AccessibilityNodeInfoCompat.ACTION_CLICK);


    I am using this code for simuating clicking whatsapp search button, but when I opened whatsapp window on 25-11-2018 at 4:39 nothing happened. The code was working fine when no time was alloted. But problem was that everytime whatsapp was opened the search button would get clicked. How to click on the search button only when whatsapp is opened at a specific time?










    share|improve this question



























      0












      0








      0








      @Override
      public void onAccessibilityEvent(final AccessibilityEvent event) {

      Date date = new Date(event.getEventTime());
      SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm");
      String time = format.format(date);
      String reqTime = "25/11/2018 04:39";
      if (reqTime.equals(time)) {
      Log.d("MyAccessibilityService", "onAccessibilityEvent");

      if (getRootInActiveWindow() == null) {
      return;
      }


      AccessibilityNodeInfoCompat rootInActiveWindow = AccessibilityNodeInfoCompat.wrap(getRootInActiveWindow());
      //Inspect app elements if ready

      //Search bar is covered with textview which need to be clicked
      List<AccessibilityNodeInfoCompat> clickOnQuestionMark = rootInActiveWindow.findAccessibilityNodeInfosByViewId("com.whatsapp:id/menuitem_search");
      if (clickOnQuestionMark.isEmpty() || clickOnQuestionMark == null) {
      return;
      }
      AccessibilityNodeInfoCompat clickMark = clickOnQuestionMark.get(0);
      clickMark.performAction(AccessibilityNodeInfoCompat.ACTION_CLICK);


      I am using this code for simuating clicking whatsapp search button, but when I opened whatsapp window on 25-11-2018 at 4:39 nothing happened. The code was working fine when no time was alloted. But problem was that everytime whatsapp was opened the search button would get clicked. How to click on the search button only when whatsapp is opened at a specific time?










      share|improve this question
















      @Override
      public void onAccessibilityEvent(final AccessibilityEvent event) {

      Date date = new Date(event.getEventTime());
      SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm");
      String time = format.format(date);
      String reqTime = "25/11/2018 04:39";
      if (reqTime.equals(time)) {
      Log.d("MyAccessibilityService", "onAccessibilityEvent");

      if (getRootInActiveWindow() == null) {
      return;
      }


      AccessibilityNodeInfoCompat rootInActiveWindow = AccessibilityNodeInfoCompat.wrap(getRootInActiveWindow());
      //Inspect app elements if ready

      //Search bar is covered with textview which need to be clicked
      List<AccessibilityNodeInfoCompat> clickOnQuestionMark = rootInActiveWindow.findAccessibilityNodeInfosByViewId("com.whatsapp:id/menuitem_search");
      if (clickOnQuestionMark.isEmpty() || clickOnQuestionMark == null) {
      return;
      }
      AccessibilityNodeInfoCompat clickMark = clickOnQuestionMark.get(0);
      clickMark.performAction(AccessibilityNodeInfoCompat.ACTION_CLICK);


      I am using this code for simuating clicking whatsapp search button, but when I opened whatsapp window on 25-11-2018 at 4:39 nothing happened. The code was working fine when no time was alloted. But problem was that everytime whatsapp was opened the search button would get clicked. How to click on the search button only when whatsapp is opened at a specific time?







      java android android-studio accessibilityservice






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 25 '18 at 14:31









      dferenc

      4,931122333




      4,931122333










      asked Nov 25 '18 at 11:19









      Shivansh KhareShivansh Khare

      207




      207
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You can convert to LocalDate



          LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();


          and use equals method to specific LocalDate




          Compares this LocalDate with another ensuring that the date is the same.



          Only objects of type LocalDate are compared, other types return false.







          share|improve this answer
























          • it says minimum api required for using toInstant() is 26 and above but most of the phones are running on api 24 so app would become useless for most of the phones.Any way to solve this?

            – Shivansh Khare
            Nov 25 '18 at 12:41











          • @ShivanshKhare if you can't upgrade, see stackoverflow.com/questions/49348769/…

            – user7294900
            Nov 25 '18 at 12:42











          • the software is licensed,I am downloading another emualator to try it. But isn't there another way to trigger onAccessibilityEvent() actions only when we want them to and not whenever whatsapp is opened?play.google.com/store/apps/… . How do apps like this do it? or play.google.com/store/apps/…

            – Shivansh Khare
            Nov 25 '18 at 12:59














          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466919%2fwhy-are-accessibility-service-not-working-to-take-user-actions%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You can convert to LocalDate



          LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();


          and use equals method to specific LocalDate




          Compares this LocalDate with another ensuring that the date is the same.



          Only objects of type LocalDate are compared, other types return false.







          share|improve this answer
























          • it says minimum api required for using toInstant() is 26 and above but most of the phones are running on api 24 so app would become useless for most of the phones.Any way to solve this?

            – Shivansh Khare
            Nov 25 '18 at 12:41











          • @ShivanshKhare if you can't upgrade, see stackoverflow.com/questions/49348769/…

            – user7294900
            Nov 25 '18 at 12:42











          • the software is licensed,I am downloading another emualator to try it. But isn't there another way to trigger onAccessibilityEvent() actions only when we want them to and not whenever whatsapp is opened?play.google.com/store/apps/… . How do apps like this do it? or play.google.com/store/apps/…

            – Shivansh Khare
            Nov 25 '18 at 12:59


















          0














          You can convert to LocalDate



          LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();


          and use equals method to specific LocalDate




          Compares this LocalDate with another ensuring that the date is the same.



          Only objects of type LocalDate are compared, other types return false.







          share|improve this answer
























          • it says minimum api required for using toInstant() is 26 and above but most of the phones are running on api 24 so app would become useless for most of the phones.Any way to solve this?

            – Shivansh Khare
            Nov 25 '18 at 12:41











          • @ShivanshKhare if you can't upgrade, see stackoverflow.com/questions/49348769/…

            – user7294900
            Nov 25 '18 at 12:42











          • the software is licensed,I am downloading another emualator to try it. But isn't there another way to trigger onAccessibilityEvent() actions only when we want them to and not whenever whatsapp is opened?play.google.com/store/apps/… . How do apps like this do it? or play.google.com/store/apps/…

            – Shivansh Khare
            Nov 25 '18 at 12:59
















          0












          0








          0







          You can convert to LocalDate



          LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();


          and use equals method to specific LocalDate




          Compares this LocalDate with another ensuring that the date is the same.



          Only objects of type LocalDate are compared, other types return false.







          share|improve this answer













          You can convert to LocalDate



          LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();


          and use equals method to specific LocalDate




          Compares this LocalDate with another ensuring that the date is the same.



          Only objects of type LocalDate are compared, other types return false.








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 25 '18 at 11:36









          user7294900user7294900

          24.7k123767




          24.7k123767













          • it says minimum api required for using toInstant() is 26 and above but most of the phones are running on api 24 so app would become useless for most of the phones.Any way to solve this?

            – Shivansh Khare
            Nov 25 '18 at 12:41











          • @ShivanshKhare if you can't upgrade, see stackoverflow.com/questions/49348769/…

            – user7294900
            Nov 25 '18 at 12:42











          • the software is licensed,I am downloading another emualator to try it. But isn't there another way to trigger onAccessibilityEvent() actions only when we want them to and not whenever whatsapp is opened?play.google.com/store/apps/… . How do apps like this do it? or play.google.com/store/apps/…

            – Shivansh Khare
            Nov 25 '18 at 12:59





















          • it says minimum api required for using toInstant() is 26 and above but most of the phones are running on api 24 so app would become useless for most of the phones.Any way to solve this?

            – Shivansh Khare
            Nov 25 '18 at 12:41











          • @ShivanshKhare if you can't upgrade, see stackoverflow.com/questions/49348769/…

            – user7294900
            Nov 25 '18 at 12:42











          • the software is licensed,I am downloading another emualator to try it. But isn't there another way to trigger onAccessibilityEvent() actions only when we want them to and not whenever whatsapp is opened?play.google.com/store/apps/… . How do apps like this do it? or play.google.com/store/apps/…

            – Shivansh Khare
            Nov 25 '18 at 12:59



















          it says minimum api required for using toInstant() is 26 and above but most of the phones are running on api 24 so app would become useless for most of the phones.Any way to solve this?

          – Shivansh Khare
          Nov 25 '18 at 12:41





          it says minimum api required for using toInstant() is 26 and above but most of the phones are running on api 24 so app would become useless for most of the phones.Any way to solve this?

          – Shivansh Khare
          Nov 25 '18 at 12:41













          @ShivanshKhare if you can't upgrade, see stackoverflow.com/questions/49348769/…

          – user7294900
          Nov 25 '18 at 12:42





          @ShivanshKhare if you can't upgrade, see stackoverflow.com/questions/49348769/…

          – user7294900
          Nov 25 '18 at 12:42













          the software is licensed,I am downloading another emualator to try it. But isn't there another way to trigger onAccessibilityEvent() actions only when we want them to and not whenever whatsapp is opened?play.google.com/store/apps/… . How do apps like this do it? or play.google.com/store/apps/…

          – Shivansh Khare
          Nov 25 '18 at 12:59







          the software is licensed,I am downloading another emualator to try it. But isn't there another way to trigger onAccessibilityEvent() actions only when we want them to and not whenever whatsapp is opened?play.google.com/store/apps/… . How do apps like this do it? or play.google.com/store/apps/…

          – Shivansh Khare
          Nov 25 '18 at 12:59






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466919%2fwhy-are-accessibility-service-not-working-to-take-user-actions%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()