Android Open Source - notify Accessibility Listener Service






From Project

Back to project page notify.

License

The source code is released under:

GNU General Public License

If you think the Android project notify listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.notify;
/*from   w w w  .  jav a  2s. co  m*/
import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.Notification;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Parcelable;
import android.text.format.Time;
import android.view.accessibility.AccessibilityEvent;
import org.json.JSONObject;

public class AccessibilityListenerService extends AccessibilityService {
    public static BackgroundService ba;

    public AccessibilityListenerService() {
        BackgroundService.aa = this;
    }

    public void onInterrupt() {

    }

    public void onAccessibilityEvent(AccessibilityEvent event) {
        if (this.ba == null || BackgroundService.s == null) {
            return;
        }
        Time t = new Time();
        t.setToNow();
        String event_time_hours = String.valueOf(t.hour);
        String event_time_minutes = String.valueOf(t.minute);
        if (event_time_hours.length() == 1) {
            event_time_hours = "0" + event_time_hours;
        }
        if (event_time_minutes.length() == 1) {
            event_time_minutes = "0" + event_time_minutes;
        }
        Parcelable parcel = event.getParcelableData();
        Notification n = (Notification)parcel;
        if (n == null) {
            return;
        }
        if (n.defaults == 0x0) {
            return;
        }
        ApplicationInfo ai;
        String event_appname;
        try {
            ai = this.getPackageManager().getApplicationInfo(event.getPackageName().toString(), 0);
            event_appname = this.getPackageManager().getApplicationLabel(ai).toString();
        } catch (PackageManager.NameNotFoundException e) {
            event_appname = "unknown";
        }
        String event_text = event.getText().toString().trim();
        event_text = event_text.substring(0, event_text.length() - 1).substring(1);
        if (event_text.length() == 0) {
            return;
        }
        try {
            JSONObject message = new JSONObject();
            message.put("type", "notification");
            JSONObject message1 = new JSONObject();
            message1.put("time", event_time_hours + ":" + event_time_minutes);
            message1.put("text", event_text);
            message1.put("app_name", event_appname);
            message.put("arguments", message1);
            this.ba.sendToServer(message.toString());
        } catch (Exception e) {
        }
    }

    protected void onServiceConnected() {
        AccessibilityServiceInfo info = new AccessibilityServiceInfo();
        info.feedbackType = AccessibilityServiceInfo.FEEDBACK_ALL_MASK;
        info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
        info.notificationTimeout = 100;
        setServiceInfo(info);
        if ((this.ba != null) && (this.ba.ma.accessibilityWaiting)) {
            MainActivity.ma.accessibilityWaiting = false;
            Intent intent = new Intent(this, MainActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            startActivity(intent);
        }
    }
}




Java Source Code List

com.example.notify.AccessibilityListenerService.java
com.example.notify.BackgroundService.java
com.example.notify.Broadcast.java
com.example.notify.DisplayFragments.java
com.example.notify.EnumMessage.java
com.example.notify.FragmentAccessibility.java
com.example.notify.FragmentBroadcastReconnect.java
com.example.notify.FragmentConnect.java
com.example.notify.FragmentConnected.java
com.example.notify.FragmentConnecting.java
com.example.notify.FragmentManual.java
com.example.notify.FragmentNoQrcodeScanner.java
com.example.notify.FragmentQrcodeWrong.java
com.example.notify.FragmentReconnect.java
com.example.notify.FragmentWifiWarning.java
com.example.notify.IntentBroadcastReceiver.java
com.example.notify.MainActivity.java
com.example.notify.OurUtils.java