get Device Services Map - Android android.os

Android examples for android.os:ParcelUuid

Description

get Device Services Map

Demo Code

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()) {
        String key = entry.getKey().toUpperCase();
        String value = entry.getValue();

        if (s.startsWith("0000" + key)) {
          found = true;/*from   ww  w .ja  v a2 s. c  om*/
          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