public class UssdListenerService extends AccessibilityService {
private static final String TAG = "USSDService";
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
if (!(event.getParcelableData() instanceof Notification)) {
String message = event.getText().toString();
String sourcePackageName = (String) event.getPackageName();
long timestamp = Calendar.getInstance().getTimeInMillis();
Log.e(TAG, "Toast Message" +message + "---" +sourcePackageName + "---" +timestamp);
}
}
@Override
public void onInterrupt() {
Log.e(TAG, "Service Interrupt");
}
@Override
protected void onServiceConnected() {
super.onServiceConnected();
Log.e(TAG, "onServiceConnected");
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.flags = AccessibilityServiceInfo.DEFAULT;
info.packageNames = new String[]{"com.android.phone"};
info.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED | AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
setServiceInfo(info);
}
}