Hello people,
    I want to enable and disable 3g programmatically on pressing single a
button..
below code only enable the 3g.
data.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                ConnectivityManager cm =
(ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
                //NetworkInfo ni = cm.getActiveNetworkInfo();

                try {
                    Method dataMtd;
                    dataMtd =
ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled",
boolean.class);

                    Log.d("start", "ing");
                    if(dataMtd.isAccessible()){
                        dataMtd.setAccessible(false);
                        dataMtd.invoke(cm, false);
                        Log.d("data", "off");
                        //return;

                    }
                    else    {
                        dataMtd.setAccessible(true);
                        dataMtd.invoke(cm, true);
                        Log.d("data", "on");
                    }


                } catch (NoSuchMethodException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalArgumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });

I want to disable it, when it is enabled ?

please help me out with this..


thanks in advance

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to