Android Question Extend Inline Java

Discussion in 'Android Questions' started by Amanda Sura, Jul 11, 2018 at 6:44 PM.

  1. Amanda Sura

    Amanda Sura Member Licensed User

    I'm trying to use inline java to work in conjunction with a lib extend of accessibility

    I'm trying to use inline why I could not create events for service, even looking at the NotificationListenerWrapper and WallpaperInternalService lib

    Code:
    package anywheresoftware.b4a.objects;

    import android.accessibilityservice.AccessibilityService;
    import android.util.Log;
    import android.view.accessibility.AccessibilityEvent;
    import android.view.accessibility.AccessibilityNodeInfo;
    import android.app.Service;
    import anywheresoftware.b4a.BA.*;
    import anywheresoftware.b4a.BA;
    import anywheresoftware.b4a.BA.Events;
    import anywheresoftware.b4a.AbsObjectWrapper;
    import anywheresoftware.b4a.BA.ActivityObject;
    import anywheresoftware.b4a.BA.DependsOn;
    import anywheresoftware.b4a.BA.Permissions;
    import anywheresoftware.b4a.BA.ShortName;
    import anywheresoftware.b4a.BA.Version;


        @ActivityObject
        @Version(
    1.0f)
    //    @Events(values={
    "accessibilityevent (event As string)"}) 
    public class AccessibilityMaster extends AccessibilityService {

    //    public static final String PACKAGE_NAME = "com.whatsapp.seubuceta";
       public void onAccessibilityEvent(AccessibilityEvent event) {
     
        if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
            
                if (event.getPackageName() != null && event.getClassName() != null) {
                  Log.d("Foreground App", event.getPackageName().toString());
                 BA.Log(event.getPackageName().toString());
                
            
                }
            }           
       }
      
       protected void onServiceConnected() {
       BA.Log("aaa");
       }
     
       public void onInterrupt() {
        
       }
      
    }
    Code:
    #If JAVA
    public String onServiceConnected() {
       return "Test!";
    }
    #End If
     
  2. Amanda Sura

    Amanda Sura Member Licensed User

    help
     
    Last edited: Jul 13, 2018 at 6:49 PM
  3. Amanda Sura

    Amanda Sura Member Licensed User

  4. JordiCP

    JordiCP Well-Known Member Licensed User

    Have you created a service for this?
    How does your manifest look like?
     
    Amanda Sura likes this.
  5. Amanda Sura

    Amanda Sura Member Licensed User

    Code:
    AddApplicationText(
              <
    service
             android:name=
    "AccessibilityMaster"
              android:permission=
    "android.permission.BIND_ACCESSIBILITY_SERVICE">
               <
    intent-filter>
                   <action android:name=
    "android.accessibilityservice.AccessibilityService" />
               </
    intent-filter>
               <meta-data
                   android:name=
    "android.accessibilityservice"
                   android:resource=
    "@xml/teste2" />
           </
    service>)


    CreateResource(xml, teste2,
      <?xml version=
    "1.0" encoding="utf-8"?>
    <accessibility-
    service xmlns:android="http://schemas.android.com/apk/res/android"
    android:accessibilityEventTypes=
    "typeWindowStateChanged|typeWindowContentChanged"
    android:accessibilityFlags=
    "flagDefault"
    android:accessibilityFeedbackType=
    "feedbackGeneric"
    android:notificationTimeout=
    "50"
    android:canRetrieveWindowContent=
    "true"
    /> 
    )
     
  6. moster67

    moster67 Expert Licensed User

    Wrapping the accessibility services is not an easy task, also because it's a big library.
    Anyway, I have wrapped lots of it and it is working fine. I will be publishing it in a few days.
     
    Amanda Sura and JordiCP like this.
  7. Amanda Sura

    Amanda Sura Member Licensed User

    I almost got it, but I will not give up.

    But thanks when you publish I will thank you very much.
    I'll even make a donation for you.
     
  8. moster67

    moster67 Expert Licensed User

    Well done. Don't give up but try to finish it. It is a good learning experience.
     
    JordiCP and Amanda Sura like this.
  9. Amanda Sura

    Amanda Sura Member Licensed User

    Friends I got more or less
    http://prntscr.com/k66pvh

    As soon as I finish I'll post the lib
    I just need some accessibility events, but I think it might be useful for someone so I'll post it as soon as I finish.
     
    moster67 and JordiCP like this.
  10. moster67

    moster67 Expert Licensed User

    That looks good!:)

    From what we discussed in our PMs, you should be able to get what you want in "onAccessibilityEvent".

    Something like this:

    Code:
    AccessibilityNodeInfo rootNode = getRootInActiveWindow();
    //        logViewHierarchy(getRootInActiveWindow(), 
    2);
            MyViewNodes = new ArrayList<AccessibilityNodeInfo>();
            infoNodes = new ArrayList<>();
            infoNodes.add(getEventType(
    event));
            infoNodes.add(
    String.valueOf(event.getEventTime()));
            findChildViews(rootNode);
            infoNodes.add(MyViewNodes);
            acs.ba.raiseEvent(this, acs.eventName + 
    "_ondataretrieved", new Object[]{infoNodes});
    Here I created an OnDataRetrieved-event which can be read from the service-module in B4A.
     
    JordiCP and Amanda Sura like this.
  11. Amanda Sura

    Amanda Sura Member Licensed User

    =
    Code:
    error: cannot find symbol
            MyViewNodes = new ArrayList<AccessibilityNodeInfo>();
            ^
      symbol:   variable MyViewNodes
      
    location: class AccessibilityMaster
    I was able to return a few logs now.

    I'm going to solve this problem, will I have to create a class for nodeinfo?
     
  12. moster67

    moster67 Expert Licensed User

    Sorry, my code was not just to paste.
    There are some method-calls in my code-snippet (such as findChildViews) which I did not post.
    I just posted it to give you an idea since you seem to be at a good point.
     
    Amanda Sura likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice