My app uses the WifiInfo
class to get the Wifi SSID of connected network.
If the user wants, it stores in an ArrayList
called WifiList at a position.
With a custom name, at the same position in another ArrayList called savedName.
Now, whenever I open the application, it checks if the Wifi SSID exists in the array list and shows me the particular custom name from the same position.
Both the Lists are stored in Shared Preferences via TinyDB. This is how I've been storing Data in Android. Using sqlite database seems out of sense to use for such simple application.
So what I need now is, a logic or way to save a numerous WiFi SSIDs under one custom name. Like when I connect to WiFi A or WiFi B it must show 'dog' and WiFi C for 'cat' and E,F,G for 'mouse'.
How do I store this sets of data and where do I store?
package combined.locky;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.IBinder;
import android.widget.Toast;
import java.util.ArrayList;
public class LockyService extends Service
{
//ANDROID VARIABLES
public Context context;
public static TinyDB tinyDB;
public static WifiManager wifiManager;
public static WifiInfo wifiInfo;
//PROGRAM VARIABLES
public static ArrayList<String> savedWifiList = new ArrayList<>(100);
public static ArrayList<String> savedContextList = new ArrayList<>(100);
@Override
public void onCreate()
{
//CRITICAL INITIALISATION
super.onCreate();
context = getApplicationContext();
tinyDB = new TinyDB(context);
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_BOOT_COMPLETED);
filter.addAction(Intent.ACTION_SCREEN_ON);
LockyReceiver receiver = new LockyReceiver();
registerReceiver(receiver, filter);
//ANDROID INITIALISATION
wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
wifiInfo = wifiManager.getConnectionInfo();
//FINALLY AFTER CREATING SERVICE
Toast.makeText(context, "Locky Service Created", Toast.LENGTH_SHORT).show();
}
@Override
public void onLowMemory()
{
tinyDB.putListString("savedWifiList", LockyService.savedWifiList);
tinyDB.putListString("savedContextList", LockyService.savedContextList);
super.onLowMemory();
}
@Override
public void onDestroy()
{
tinyDB.putListString("savedWifiList", LockyService.savedWifiList);
tinyDB.putListString("savedContextList", LockyService.savedContextList);
Toast.makeText(context, "Locky Service Killed", Toast.LENGTH_SHORT).show();
super.onDestroy();
}
@Override
public IBinder onBind(Intent intent)
{
return null;
}
}
here's the example code above where I am using arraylists. I want to map one name to different saved Wifi SSIDs. I have no idea where to start.