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();
}
};
}
}
}