FileDocCategorySizeDatePackage
BluetoothMapEventReport.javaAPI DocAndroid 5.1 API6873Thu Mar 12 22:22:50 GMT 2015android.bluetooth.client.map

BluetoothMapEventReport

public class BluetoothMapEventReport extends Object
Object representation of event report received by MNS

This object will be received in {@link BluetoothMasClient#EVENT_EVENT_REPORT} callback message.

Fields Summary
private static final String
TAG
private final Type
mType
private final String
mHandle
private final String
mFolder
private final String
mOldFolder
private final BluetoothMapBmessage.Type
mMsgType
Constructors Summary
private BluetoothMapEventReport(HashMap attrs)

        mType = parseType(attrs.get("type"));

        if (mType != Type.MEMORY_FULL && mType != Type.MEMORY_AVAILABLE) {
            String handle = attrs.get("handle");
            try {
                /* just to validate */
                new BigInteger(attrs.get("handle"), 16);

                mHandle = attrs.get("handle");
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException("Invalid value for handle:" + handle);
            }
        } else {
            mHandle = null;
        }

        mFolder = attrs.get("folder");

        mOldFolder = attrs.get("old_folder");

        if (mType != Type.MEMORY_FULL && mType != Type.MEMORY_AVAILABLE) {
            String s = attrs.get("msg_type");

            if ("".equals(s)) {
                // Some phones (e.g. SGS3 for MessageDeleted) send empty
                // msg_type, in such case leave it as null rather than throw
                // parse exception
                mMsgType = null;
            } else {
                mMsgType = parseMsgType(s);
            }
        } else {
            mMsgType = null;
        }
    
Methods Summary
static android.bluetooth.client.map.BluetoothMapEventReportfromStream(java.io.DataInputStream in)

        BluetoothMapEventReport ev = null;

        try {
            XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser();
            xpp.setInput(in, "utf-8");

            int event = xpp.getEventType();
            while (event != XmlPullParser.END_DOCUMENT) {
                switch (event) {
                    case XmlPullParser.START_TAG:
                        if (xpp.getName().equals("event")) {
                            HashMap<String, String> attrs = new HashMap<String, String>();

                            for (int i = 0; i < xpp.getAttributeCount(); i++) {
                                attrs.put(xpp.getAttributeName(i), xpp.getAttributeValue(i));
                            }

                            ev = new BluetoothMapEventReport(attrs);

                            // return immediately, only one event should be here
                            return ev;
                        }
                        break;
                }

                event = xpp.next();
            }

        } catch (XmlPullParserException e) {
            Log.e(TAG, "XML parser error when parsing XML", e);
        } catch (IOException e) {
            Log.e(TAG, "I/O error when parsing XML", e);
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "Invalid event received", e);
        }

        return ev;
    
public java.lang.StringgetFolder()

return
value corresponding to folder parameter in MAP specification

        return mFolder;
    
public java.lang.StringgetHandle()

return
value corresponding to handle parameter in MAP specification

        return mHandle;
    
public BluetoothMapBmessage.TypegetMsgType()

return
{@link BluetoothMapBmessage.Type} object corresponding to msg_type application parameter in MAP specification

        return mMsgType;
    
public java.lang.StringgetOldFolder()

return
value corresponding to old_folder parameter in MAP specification

        return mOldFolder;
    
public android.bluetooth.client.map.BluetoothMapEventReport$TypegetType()

return
{@link BluetoothMapEventReport.Type} object corresponding to type application parameter in MAP specification

        return mType;
    
private BluetoothMapBmessage.TypeparseMsgType(java.lang.String msgType)

        for (BluetoothMapBmessage.Type t : BluetoothMapBmessage.Type.values()) {
            if (t.name().equals(msgType)) {
                return t;
            }
        }

        throw new IllegalArgumentException("Invalid value for msg_type: " + msgType);
    
private android.bluetooth.client.map.BluetoothMapEventReport$TypeparseType(java.lang.String type)

        for (Type t : Type.values()) {
            if (t.toString().equals(type)) {
                return t;
            }
        }

        throw new IllegalArgumentException("Invalid value for type: " + type);
    
public java.lang.StringtoString()

        JSONObject json = new JSONObject();

        try {
            json.put("type", mType);
            json.put("handle", mHandle);
            json.put("folder", mFolder);
            json.put("old_folder", mOldFolder);
            json.put("msg_type", mMsgType);
        } catch (JSONException e) {
            // do nothing
        }

        return json.toString();