1

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.

Sharukh Mohammed
  • 365
  • 2
  • 16

2 Answers2

0

I didn't figure out what exact your problem so please Clarey more in order to offer a specific help for you but as per my understanding for you question:

The size of data you want to store is not large so i think shared preferences is the best solution and you already using it.

Another solution is to store your data in a file and read/write from it.

If you have a complex relational data you should use SQLite for that.

You can also use Realm it's simple and efficient data store solution also there is SnappyDB it's an alternative for SQLite if you want to use a NoSQL approach.

but for a small amount key/value pairs of data shared preferences is the best solution also you can use TinyDB to simplifies calls to SharedPreferences in a line of code.

If your problem is how to store and retrieve ArrayList from SharedPreferences you can check this question

Community
  • 1
  • 1
Marzouk
  • 2,650
  • 3
  • 25
  • 56
  • I am currently using TinyDB. However, that's not the porblem, I need a specific _idea_ or _logic_, how I can store data and relate. – Sharukh Mohammed Mar 09 '16 at 05:04
  • @sharukhmohammed please check the edit on answer and let me know if that's help. – Marzouk Mar 09 '16 at 09:08
  • My problem isn't finding a method to store the data. But a logic for _how to map different SSIDs under category **home**_ . Which data types to use and how to link them so that WIFI SSID 1,2,3 points to **home** and 4,5 points to **office** and 6 points to **home** again and so on. Help would be greatly appreciated. – Sharukh Mohammed Mar 10 '16 at 07:33
-3

If you want to store the data locally, you can simply go with a SQLite database. It works in Android as well as iOS, and is easy to store and manage.

William Price
  • 4,033
  • 1
  • 35
  • 54
Siva
  • 1
  • 2