On May 13, 2011, at 3:17 PM, dbeaugrand wrote:
> I have a need to monitor the state of the network connections in my 
> application. I have setup a BroadcastReceiver on 
> ConnectivityManager.ConnectivityAction to do this. 
...
> But the JAVA example i was following uses getParcelableExtra to obtain the 
> NetworkInfo. 
> 
> @Override
>  public void onReceive(Context arg0, Intent arg1) {
> 
>   NetworkInfo networkInfo = (NetworkInfo)
> arg1.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
>   if(networkInfo.getType() == ConnectivityManager.TYPE_WIFI){
>    DisplayWifiState();
>   }
> 
> I can only find a GetParcelableArrayExtra in monodroid API. Can someone point 
> me to a monodroid way of getting the NetworkInfo from the OnReceive Intent?

Due to a generator limitation, Intent.getParcelableExtra() isn't bound. 
Consequently, you'll need to use JNI to invoke this member (untested):

        IntPtr getParcelableExtra = JNIEnv.GetMethodID (arg1.Class.Handle,
                        "getParcelableExtra", 
"(Ljava/lang/String;)Landroid/os/Parcelable;");
        IntPtr _ni = JNIEnv.CallObjectMethod (arg1.Handle, getParcelableExtra,
                        new JValue (new Java.Lang.String 
(ConnectivityManager.ExtraNetworkInfo)));
        NetworkInfo networkInfo = new NetworkInfo (_ni);

 - Jon

_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to