0

I am developing a android app where I need to check whether the android device is connected to a particular network to start the app. For example, If the android device is connected to a network say "JK20" then the app can be opened successfully otherwise it will throw an error saying that please connect to the "JK20" network.

The code I am wrinting is in C#. Please help with code snippets.

Below is my code snippet:

namespace Test_Launcher { [Activity (Label = "Test_Launcher", MainLauncher = true, Icon = "@drawable/icon")] public class MainActivity : Activity {

    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);

        // Set our view from the "main" layout resource
        SetContentView (Resource.Layout.Main);

        // Get our button from the layout resource,
        // and attach an event to it
        Button button = FindViewById<Button> (Resource.Id.button1);


        button.Click += delegate {
            var cm = (ConnectivityManager)GetSystemService(ConnectivityService);
            var activeConnection = cm.ActiveNetworkInfo;
            WifiConfiguration wifiConfiguration = new WifiConfiguration();

            if ((activeConnection != null)  && activeConnection.IsConnected && NetworkSSID == 'JK20') // here what code should be to check for NetworkSSID
            {
                var uri = Android.Net.Uri.Parse ("http://www.google.co.in");
                var intent = new Intent (Intent.ActionView, uri); 
                StartActivity (intent);
            }

            else{
                var builder = new AlertDialog.Builder(this);
                builder.SetMessage("Please connect to JK20 to proceed");
                builder.SetPositiveButton("OK", (s, e) => { });
                builder.SetNegativeButton("Cancel", (s1, e1) => { });
                builder.Create().Show();
            }
        };
    }
}

}

  • what hv u tried in android any code? can u post? or refere this http://stackoverflow.com/questions/24697533/manual-proxy-in-android-through-reflection/24797025#24797025 – KOTIOS Aug 19 '14 at 10:07
  • OR http://stackoverflow.com/questions/25141229/change-internet-proxy-wifi-3g-gprs-in-android-2-2-an-upper-from-code – KOTIOS Aug 19 '14 at 10:10
  • I am just writing a wrapper code for an URL. for Example, if(network=='JK20'){//open the url} else {//give error } – user3766186 Aug 19 '14 at 10:20
  • m interested to know android side code and functionality – KOTIOS Aug 19 '14 at 10:22
  • yes thats sinple scan if connected network and if connect open ur url else ur error msg – KOTIOS Aug 19 '14 at 10:33
  • Yes. We directly cant give NetworkSSID == 'JK20. Can you tell me what exact condition will come ? – user3766186 Aug 19 '14 at 10:35

1 Answers1

0

Get the connected ssid and compare it like :

WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
Log.d("wifiInfo", wifiInfo.toString());
Log.d("SSID",wifiInfo.getSSID());

if(wifiInfo.getSSID().equals("JK20"))
{
//redirect ur url
}
else
{
// toast a msg
}
KOTIOS
  • 11,177
  • 3
  • 39
  • 66