Thank you all, I figured out how to do it
on Java
(http://manski.net/2012/03/30/accessing-java-classes-from-mono-for-android-via-jni/)
create library

package com.mayastudios.jnitest;

import android.content.Context;
import android.net.ConnectivityManager;
import java.lang.reflect.Method;

public class JniTest {
  
  public JniTest() { 
    // Force the user to create an instance
  }
  
  public String getGreetingText() {
    return "Hello, 333 " + android.os.Build.MODEL;
  }
  
  public void setMobileDataEnabled(Context paramContext,boolean on)
  {
      try {

          ConnectivityManager connectivityManager = 
(ConnectivityManager)paramContext.getSystemService("connectivity");

          Method method =
connectivityManager.getClass().getMethod("setMobileDataEnabled",
boolean.class);
          method.invoke(connectivityManager, on);
      } catch (NoSuchMethodException e)
      {
          e.printStackTrace();
      } catch (Exception e)
      {
          e.printStackTrace();
      }
  }
  
  public  boolean getMobileDataEnabled(Context paramContext)
  {
      try {
          ConnectivityManager connectivityManager = 
(ConnectivityManager)paramContext.getSystemService("connectivity");
          Method method =
connectivityManager.getClass().getMethod("getMobileDataEnabled");
          return (Boolean) method.invoke(connectivityManager);
      } catch (Exception e) {
          e.printStackTrace();
          return false;
      }

  }
}

on VS

    void EnableGPRS(Context ct)
    {
        bool on = false;

        IntPtr nativeJavaClass =
JNIEnv.FindClass("com/mayastudios/jnitest/JniTest");

        IntPtr defaultConstructor = JNIEnv.GetMethodID(nativeJavaClass,
"<init>", "()V");

        IntPtr instance = JNIEnv.NewObject(nativeJavaClass,
defaultConstructor);


        //IntPtr method1 = JNIEnv.GetMethodID(nativeJavaClass,
"getGreetingText", "()Ljava/lang/String;");
        IntPtr method1 =  JNIEnv.GetMethodID(nativeJavaClass,
"getMobileDataEnabled", "(Landroid/content/Context;)Z");
        on = JNIEnv.CallBooleanMethod(instance, method1, new JValue(ct));

        IntPtr method = JNIEnv.GetMethodID(nativeJavaClass,
"setMobileDataEnabled", "(Landroid/content/Context;Z)V");

        JValue[] p = new JValue[] { new JValue(ct), new JValue(!on) }; 
  

        IntPtr resultPtr = JNIEnv.CallObjectMethod(instance, method,p);
    }



--
View this message in context: 
http://mono-for-android.1047100.n5.nabble.com/How-to-change-the-network-state-of-device-tp5711776p5711793.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
[email protected]

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

Reply via email to