Question

I'm trying to create my own ImagePreference that I will use in my app preferences in order to pick the picture the user chooses to represent himself.

I'm not too sure about what I'm doing, but basically I'm mimicking some other preference classes. So far I'm only having trouble with this method:

public class ImagePreference extends Preference {
...
    void sendAccessibilityEvent(View view) {
        // Since the view is still not attached we create, populate,
        // and send the event directly since we do not know when it
        // will be attached and posting commands is not as clean.
        AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(getContext());
        if (mSendClickAccessibilityEvent && accessibilityManager.isEnabled()) {
            AccessibilityEvent event = AccessibilityEvent.obtain();
            event.setEventType(AccessibilityEvent.TYPE_VIEW_CLICKED);
            view.onInitializeAccessibilityEvent(event);
            view.dispatchPopulateAccessibilityEvent(event);
            accessibilityManager.sendAccessibilityEvent(event);
        }
        mSendClickAccessibilityEvent = false;
    }

I have just copied this code from the TwoStatePreference class. I'm not even sure I need this method at all, but the compiler complains saying that the AccessibilityManager class does not contain a getInstance method.

I thought this could be a problem with the imports, but I'm importing the same classes as TwoStatePreference does, i.e.:

import android.view.accessibility.AccessibilityManager;

I have lost already several hours with this problem. Any idea of why the compiler is complaining?

Thanks!

Was it helpful?

Solution

Indeed, the AccessibilityManager class has no method called getInstance(). From the docs:

To obtain a handle to the accessibility manager do the following:

AccessibilityManager accessibilityManager =
    (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);

So really all you need is a Context. Lucky, you've got a View, which itself is a Context, and holds references to it's parent contexts.

OTHER TIPS

This method had been hidden. The source code:

 /**
 * Get an AccessibilityManager instance (create one if necessary).
 *
 * @param context Context in which this manager operates.
 *
 * @hide
 */
public static AccessibilityManager getInstance(Context context)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top