Bug 10010 - Calling inputManager.RegisterInputDeviceListener always gives "listener must not be null" error
Summary: Calling inputManager.RegisterInputDeviceListener always gives "listener must ...
Status: RESOLVED INVALID
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.4.x
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Atsushi Eno
URL:
Depends on:
Blocks:
 
Reported: 2013-02-04 05:21 UTC by David Leaver
Modified: 2013-06-24 12:03 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description David Leaver 2013-02-04 05:21:10 UTC
Calling inputManager.RegisterInputDeviceListener always fails with the error:

Unhandled Exception:
Java.Lang.IllegalArgumentException: listener must not be null

Which makes me think the binding is screwed up, as the error should only come up if you pass null and I'm definitely not.
https://github.com/android/platform_frameworks_base/blob/master/core/java/android/hardware/input/InputManager.java#L283


Example code follows, just call InputDeviceListener.Init(context);

internal class InputDeviceListener : InputManager.IInputDeviceListener
{
	public static void Init(Context context)
	{
		var inputManager = (InputManager)context.GetSystemService("input");

		inputManager.RegisterInputDeviceListener(new InputDeviceListener(), null);
	}


	public void Dispose()
	{
	}

	public IntPtr Handle { get; private set; }
	public void OnInputDeviceAdded(int deviceId)
	{
		var device = InputDevice.GetDevice(deviceId);
		//GetGamePad(device);
	}

	public void OnInputDeviceChanged(int deviceId)
	{
	}

	public void OnInputDeviceRemoved(int deviceId)
	{
		//ForgetGamePad(deviceId);
	}
}


My test device is an OUYA console, which is running Android 4.1.2.
Thanks guys :-)
Comment 1 David Leaver 2013-02-04 05:26:11 UTC
Related bug on the MonoGame project:
https://github.com/mono/MonoGame/issues/1171#issuecomment-13069858
Comment 2 Atsushi Eno 2013-06-21 05:37:12 UTC
I couldn't reproduce this issue. I don't have OUYA so I tried only on my JellyBean emulator though. I'm asking some other people to try.

AOSP is not always fully used, so there might be still some difference in the code running on your device.
Comment 4 Jonathan Pryor 2013-06-24 12:03:23 UTC
You MUST NOT implement IJavaObject yourself.

http://androidapi.xamarin.com/?link=T%3aAndroid.Runtime.IJavaObject
> NEVER IMPLEMENT THIS INTERFACE YOURSELF. Implement this interface
> by inheriting from Java.Lang.Object.

IJavaObject.Handle is a reference to the Java-VM object. InputDeviceListener never sets it, and thus it will always be IntPtr.Zero, i.e. `null`, which is why InputManager.RegisterInputDeviceListener() throws an IllegalArgumentException.