get Bluetooth Device Services Map - Android Bluetooth

Android examples for Bluetooth:Bluetooth Device

Description

get Bluetooth Device Services Map

Demo Code


//package com.java2s;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import android.os.ParcelUuid;

public class Main {
    private static Map<String, String> uuidsDescriptions = new HashMap<String, String>();

    public static HashMap<String, String> getDeviceServicesMap(
            ArrayList<ParcelUuid> uuids) {
        HashMap<String, String> result = new HashMap<String, String>();

        for (ParcelUuid uuid : uuids) {
            String s = uuid.toString().toUpperCase();
            boolean found = false;

            for (Map.Entry<String, String> entry : uuidsDescriptions
                    .entrySet()) {/*  ww w .  j  av  a 2  s .  c o m*/
                String key = entry.getKey().toUpperCase();
                String value = entry.getValue();

                if (s.startsWith("0000" + key)) {
                    found = true;
                    result.put(key, value);
                    break;
                }
            }

            if (!found) {
                String key = s.substring(4, 8);
                String desc = "Unknown service UUID 0x" + key;
                result.put(key, desc);
            }
        }

        return result;
    }
}

Related Tutorials