Android Open Source - AndroidBleLib Ble Prefs






From Project

Back to project page AndroidBleLib.

License

The source code is released under:

MIT License

If you think the Android project AndroidBleLib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package io.hearty.ble.lib.utils;
// ww  w.j  av a2s.c  om
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.SharedPreferences;
import com.google.gson.Gson;

/**
 * Created by ejf3 on 5/18/14.
 */
public class BlePrefs {
    private static final String TAG = "BlePrefs";

    private static final String BLE_DEVICE = "ble_device";

    private SharedPreferences preferences;

    public BlePrefs(Context context) {
        preferences = context
                .getSharedPreferences("auth", Context.MODE_PRIVATE);
    }

    public void setConnectedDevice(BluetoothDevice device) {
        Gson gson = new Gson();
        String objStr = gson.toJson(device);

        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(BLE_DEVICE, objStr);
        editor.commit();
    }

    public BluetoothDevice getConnectedDevice() {
        String objStr = preferences.getString(BLE_DEVICE, null);
        if (null == objStr)
            return null;

        Gson gson = new Gson();
        return gson.fromJson(objStr, BluetoothDevice.class);
    }

}




Java Source Code List

io.hearty.ble.lib.BleScanner.java
io.hearty.ble.lib.data.BleConnect.java
io.hearty.ble.lib.data.DeviceFound.java
io.hearty.ble.lib.data.HeartRate.java
io.hearty.ble.lib.data.StoredBluetoothDevice.java
io.hearty.ble.lib.heart.BleHeartService.java
io.hearty.ble.lib.utils.BlePrefs.java
io.hearty.ble.lib.utils.BleUtils.java
io.hearty.ble.lib.utils.SampleGattAttributes.java