Jon, thank you very much for your solution that is working fine.
PedroC
Jonathan Pryor wrote:
On Oct 7, 2011, at 1:10 PM, G.B. wrote:
As Monodroid has not implemented that method, I found in the Forum, a similar problem in the case of NetworkInfo. Trying to do the same I end up with:
IntPtr getParcelableExtra = JNIEnv.GetMethodID(intent.Class.Handle, "getParcelableExtra", "(Ljava/lang/String;)Landroid/os/Parcelable;");
IntPtr _ni = JNIEnv.CallObjectMethod(intent.Handle, getParcelableExtra, new JValue(new Java.Lang.String(BluetoothDevice.ExtraDevice)));
BluetoothDevice device = new BluetoothDevice(_ni);
But the last method has no IntPtr parameter (_ni) to use....
The solution is to use the JavaCast<T>()[0] extension method:
var device = new Java.Lang.Object(_ni).JavaCast<BluetoothDevice>();
The reason we do it that way is because people wanted to create an instance of a type,
saw the (IntPtr) constructor, and would do "silly" things such as:
var v = new BluetoothDevice (IntPtr.Zero);
then ask why they were getting java.lang.NullPointerExceptions when they used
`v`. To avoid this scenario, we hide the (IntPtr) constructor on sealed/etc.
types.
- Jon
[0]
http://docs.mono-android.net/index.aspx?link=M%3aAndroid.Runtime.Extensions.JavaCast``1(Android.Runtime.IJavaObject)
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
---
avast! Antivirus: Inbound message clean.
Virus Database (VPS): 111003-0, 03-10-2011
Tested on: 07-10-2011 18:23:34
avast! - copyright (c) 1988-2011 AVAST Software.
http://www.avast.com
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid