FileDocCategorySizeDatePackage
CellBroadcastMessage.javaAPI DocAndroid 5.1 API16195Thu Mar 12 22:22:54 GMT 2015android.telephony

CellBroadcastMessage

public class CellBroadcastMessage extends Object implements android.os.Parcelable
Application wrapper for {@link SmsCbMessage}. This is Parcelable so that decoded broadcast message objects can be passed between running Services. New broadcasts are received by the CellBroadcastReceiver app, which exports the database of previously received broadcasts at "content://cellbroadcasts/". The "android.permission.READ_CELL_BROADCASTS" permission is required to read from the ContentProvider, and writes to the database are not allowed.

Use {@link #createFromCursor} to create CellBroadcastMessage objects from rows in the database cursor returned by the ContentProvider. {@hide}

Fields Summary
public static final String
SMS_CB_MESSAGE_EXTRA
Identifier for getExtra() when adding this object to an Intent.
private final SmsCbMessage
mSmsCbMessage
SmsCbMessage.
private final long
mDeliveryTime
private boolean
mIsRead
private int
mSubId
Indicates the subId
public static final Parcelable.Creator
CREATOR
Constructors Summary
public CellBroadcastMessage(SmsCbMessage message)

        mSmsCbMessage = message;
        mDeliveryTime = System.currentTimeMillis();
        mIsRead = false;
    
private CellBroadcastMessage(SmsCbMessage message, long deliveryTime, boolean isRead)

        mSmsCbMessage = message;
        mDeliveryTime = deliveryTime;
        mIsRead = isRead;
    
private CellBroadcastMessage(android.os.Parcel in)

        mSmsCbMessage = new SmsCbMessage(in);
        mDeliveryTime = in.readLong();
        mIsRead = (in.readInt() != 0);
    
Methods Summary
public static android.telephony.CellBroadcastMessagecreateFromCursor(android.database.Cursor cursor)
Create a CellBroadcastMessage from a row in the database.

param
cursor an open SQLite cursor pointing to the row to read
return
the new CellBroadcastMessage
throws
IllegalArgumentException if one of the required columns is missing


                                            
         
        int geoScope = cursor.getInt(
                cursor.getColumnIndexOrThrow(Telephony.CellBroadcasts.GEOGRAPHICAL_SCOPE));
        int serialNum = cursor.getInt(
                cursor.getColumnIndexOrThrow(Telephony.CellBroadcasts.SERIAL_NUMBER));
        int category = cursor.getInt(
                cursor.getColumnIndexOrThrow(Telephony.CellBroadcasts.SERVICE_CATEGORY));
        String language = cursor.getString(
                cursor.getColumnIndexOrThrow(Telephony.CellBroadcasts.LANGUAGE_CODE));
        String body = cursor.getString(
                cursor.getColumnIndexOrThrow(Telephony.CellBroadcasts.MESSAGE_BODY));
        int format = cursor.getInt(
                cursor.getColumnIndexOrThrow(Telephony.CellBroadcasts.MESSAGE_FORMAT));
        int priority = cursor.getInt(
                cursor.getColumnIndexOrThrow(Telephony.CellBroadcasts.MESSAGE_PRIORITY));

        String plmn;
        int plmnColumn = cursor.getColumnIndex(Telephony.CellBroadcasts.PLMN);
        if (plmnColumn != -1 && !cursor.isNull(plmnColumn)) {
            plmn = cursor.getString(plmnColumn);
        } else {
            plmn = null;
        }

        int lac;
        int lacColumn = cursor.getColumnIndex(Telephony.CellBroadcasts.LAC);
        if (lacColumn != -1 && !cursor.isNull(lacColumn)) {
            lac = cursor.getInt(lacColumn);
        } else {
            lac = -1;
        }

        int cid;
        int cidColumn = cursor.getColumnIndex(Telephony.CellBroadcasts.CID);
        if (cidColumn != -1 && !cursor.isNull(cidColumn)) {
            cid = cursor.getInt(cidColumn);
        } else {
            cid = -1;
        }

        SmsCbLocation location = new SmsCbLocation(plmn, lac, cid);

        SmsCbEtwsInfo etwsInfo;
        int etwsWarningTypeColumn = cursor.getColumnIndex(
                Telephony.CellBroadcasts.ETWS_WARNING_TYPE);
        if (etwsWarningTypeColumn != -1 && !cursor.isNull(etwsWarningTypeColumn)) {
            int warningType = cursor.getInt(etwsWarningTypeColumn);
            etwsInfo = new SmsCbEtwsInfo(warningType, false, false, null);
        } else {
            etwsInfo = null;
        }

        SmsCbCmasInfo cmasInfo;
        int cmasMessageClassColumn = cursor.getColumnIndex(
                Telephony.CellBroadcasts.CMAS_MESSAGE_CLASS);
        if (cmasMessageClassColumn != -1 && !cursor.isNull(cmasMessageClassColumn)) {
            int messageClass = cursor.getInt(cmasMessageClassColumn);

            int cmasCategory;
            int cmasCategoryColumn = cursor.getColumnIndex(
                    Telephony.CellBroadcasts.CMAS_CATEGORY);
            if (cmasCategoryColumn != -1 && !cursor.isNull(cmasCategoryColumn)) {
                cmasCategory = cursor.getInt(cmasCategoryColumn);
            } else {
                cmasCategory = SmsCbCmasInfo.CMAS_CATEGORY_UNKNOWN;
            }

            int responseType;
            int cmasResponseTypeColumn = cursor.getColumnIndex(
                    Telephony.CellBroadcasts.CMAS_RESPONSE_TYPE);
            if (cmasResponseTypeColumn != -1 && !cursor.isNull(cmasResponseTypeColumn)) {
                responseType = cursor.getInt(cmasResponseTypeColumn);
            } else {
                responseType = SmsCbCmasInfo.CMAS_RESPONSE_TYPE_UNKNOWN;
            }

            int severity;
            int cmasSeverityColumn = cursor.getColumnIndex(
                    Telephony.CellBroadcasts.CMAS_SEVERITY);
            if (cmasSeverityColumn != -1 && !cursor.isNull(cmasSeverityColumn)) {
                severity = cursor.getInt(cmasSeverityColumn);
            } else {
                severity = SmsCbCmasInfo.CMAS_SEVERITY_UNKNOWN;
            }

            int urgency;
            int cmasUrgencyColumn = cursor.getColumnIndex(
                    Telephony.CellBroadcasts.CMAS_URGENCY);
            if (cmasUrgencyColumn != -1 && !cursor.isNull(cmasUrgencyColumn)) {
                urgency = cursor.getInt(cmasUrgencyColumn);
            } else {
                urgency = SmsCbCmasInfo.CMAS_URGENCY_UNKNOWN;
            }

            int certainty;
            int cmasCertaintyColumn = cursor.getColumnIndex(
                    Telephony.CellBroadcasts.CMAS_CERTAINTY);
            if (cmasCertaintyColumn != -1 && !cursor.isNull(cmasCertaintyColumn)) {
                certainty = cursor.getInt(cmasCertaintyColumn);
            } else {
                certainty = SmsCbCmasInfo.CMAS_CERTAINTY_UNKNOWN;
            }

            cmasInfo = new SmsCbCmasInfo(messageClass, cmasCategory, responseType, severity,
                    urgency, certainty);
        } else {
            cmasInfo = null;
        }

        SmsCbMessage msg = new SmsCbMessage(format, geoScope, serialNum, location, category,
                language, body, priority, etwsInfo, cmasInfo);

        long deliveryTime = cursor.getLong(cursor.getColumnIndexOrThrow(
                Telephony.CellBroadcasts.DELIVERY_TIME));
        boolean isRead = (cursor.getInt(cursor.getColumnIndexOrThrow(
                Telephony.CellBroadcasts.MESSAGE_READ)) != 0);

        return new CellBroadcastMessage(msg, deliveryTime, isRead);
    
public intdescribeContents()
Parcelable: no special flags.

        return 0;
    
public intgetCmasMessageClass()
Return the CMAS message class.

return
the CMAS message class, e.g. {@link SmsCbCmasInfo#CMAS_CLASS_SEVERE_THREAT}, or {@link SmsCbCmasInfo#CMAS_CLASS_UNKNOWN} if this is not a CMAS alert

        if (mSmsCbMessage.isCmasMessage()) {
            return mSmsCbMessage.getCmasWarningInfo().getMessageClass();
        } else {
            return SmsCbCmasInfo.CMAS_CLASS_UNKNOWN;
        }
    
public SmsCbCmasInfogetCmasWarningInfo()

        return mSmsCbMessage.getCmasWarningInfo();
    
public android.content.ContentValuesgetContentValues()
Return a ContentValues object for insertion into the database.

return
a new ContentValues object containing this object's data

        ContentValues cv = new ContentValues(16);
        SmsCbMessage msg = mSmsCbMessage;
        cv.put(Telephony.CellBroadcasts.GEOGRAPHICAL_SCOPE, msg.getGeographicalScope());
        SmsCbLocation location = msg.getLocation();
        if (location.getPlmn() != null) {
            cv.put(Telephony.CellBroadcasts.PLMN, location.getPlmn());
        }
        if (location.getLac() != -1) {
            cv.put(Telephony.CellBroadcasts.LAC, location.getLac());
        }
        if (location.getCid() != -1) {
            cv.put(Telephony.CellBroadcasts.CID, location.getCid());
        }
        cv.put(Telephony.CellBroadcasts.SERIAL_NUMBER, msg.getSerialNumber());
        cv.put(Telephony.CellBroadcasts.SERVICE_CATEGORY, msg.getServiceCategory());
        cv.put(Telephony.CellBroadcasts.LANGUAGE_CODE, msg.getLanguageCode());
        cv.put(Telephony.CellBroadcasts.MESSAGE_BODY, msg.getMessageBody());
        cv.put(Telephony.CellBroadcasts.DELIVERY_TIME, mDeliveryTime);
        cv.put(Telephony.CellBroadcasts.MESSAGE_READ, mIsRead);
        cv.put(Telephony.CellBroadcasts.MESSAGE_FORMAT, msg.getMessageFormat());
        cv.put(Telephony.CellBroadcasts.MESSAGE_PRIORITY, msg.getMessagePriority());

        SmsCbEtwsInfo etwsInfo = mSmsCbMessage.getEtwsWarningInfo();
        if (etwsInfo != null) {
            cv.put(Telephony.CellBroadcasts.ETWS_WARNING_TYPE, etwsInfo.getWarningType());
        }

        SmsCbCmasInfo cmasInfo = mSmsCbMessage.getCmasWarningInfo();
        if (cmasInfo != null) {
            cv.put(Telephony.CellBroadcasts.CMAS_MESSAGE_CLASS, cmasInfo.getMessageClass());
            cv.put(Telephony.CellBroadcasts.CMAS_CATEGORY, cmasInfo.getCategory());
            cv.put(Telephony.CellBroadcasts.CMAS_RESPONSE_TYPE, cmasInfo.getResponseType());
            cv.put(Telephony.CellBroadcasts.CMAS_SEVERITY, cmasInfo.getSeverity());
            cv.put(Telephony.CellBroadcasts.CMAS_URGENCY, cmasInfo.getUrgency());
            cv.put(Telephony.CellBroadcasts.CMAS_CERTAINTY, cmasInfo.getCertainty());
        }

        return cv;
    
public java.lang.StringgetDateString(android.content.Context context)
Return the abbreviated date string for the message delivery time.

param
context the context object
return
a String to use in the broadcast list UI

        int flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_SHOW_TIME |
                DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_DATE |
                DateUtils.FORMAT_CAP_AMPM;
        return DateUtils.formatDateTime(context, mDeliveryTime, flags);
    
public longgetDeliveryTime()

        return mDeliveryTime;
    
public SmsCbEtwsInfogetEtwsWarningInfo()

        return mSmsCbMessage.getEtwsWarningInfo();
    
public java.lang.StringgetLanguageCode()

        return mSmsCbMessage.getLanguageCode();
    
public java.lang.StringgetMessageBody()

        return mSmsCbMessage.getMessageBody();
    
public intgetSerialNumber()

        return mSmsCbMessage.getSerialNumber();
    
public intgetServiceCategory()

        return mSmsCbMessage.getServiceCategory();
    
public java.lang.StringgetSpokenDateString(android.content.Context context)
Return the date string for the message delivery time, suitable for text-to-speech.

param
context the context object
return
a String for populating the list item AccessibilityEvent for TTS

        int flags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE;
        return DateUtils.formatDateTime(context, mDeliveryTime, flags);
    
public intgetSubId()
get Subscription information

hide

        return mSubId;
    
public booleanisCmasMessage()
Return whether the broadcast is a CMAS emergency message type.

return
true if the message is CMAS emergency type; false otherwise

        return mSmsCbMessage.isCmasMessage();
    
public booleanisEmergencyAlertMessage()
Returns whether the broadcast is an emergency (PWS) message type, including test messages and AMBER alerts.

return
true if the message is PWS type (ETWS or CMAS)

        return mSmsCbMessage.isEmergencyMessage();
    
public booleanisEtwsEmergencyUserAlert()
Return whether the broadcast is an ETWS emergency user alert. This method checks the message ID and the message code.

return
true if the message indicates an ETWS emergency user alert

        SmsCbEtwsInfo etwsInfo = mSmsCbMessage.getEtwsWarningInfo();
        return etwsInfo != null && etwsInfo.isEmergencyUserAlert();
    
public booleanisEtwsMessage()
Return whether the broadcast is an ETWS emergency message type.

return
true if the message is ETWS emergency type; false otherwise

        return mSmsCbMessage.isEtwsMessage();
    
public booleanisEtwsPopupAlert()
Return whether the broadcast is an ETWS popup alert. This method checks the message ID and the message code.

return
true if the message indicates an ETWS popup alert

        SmsCbEtwsInfo etwsInfo = mSmsCbMessage.getEtwsWarningInfo();
        return etwsInfo != null && etwsInfo.isPopupAlert();
    
public booleanisEtwsTestMessage()
Return whether the broadcast is an ETWS test message.

return
true if the message is an ETWS test message; false otherwise

        SmsCbEtwsInfo etwsInfo = mSmsCbMessage.getEtwsWarningInfo();
        return etwsInfo != null &&
                etwsInfo.getWarningType() == SmsCbEtwsInfo.ETWS_WARNING_TYPE_TEST_MESSAGE;
    
public booleanisPublicAlertMessage()
Return whether the broadcast is an emergency (PWS) message type. This includes lower priority test messages and Amber alerts. All public alerts show the flashing warning icon in the dialog, but only emergency alerts play the alert sound and speak the message.

return
true if the message is PWS type; false otherwise

        return mSmsCbMessage.isEmergencyMessage();
    
public booleanisRead()

        return mIsRead;
    
public voidsetIsRead(boolean isRead)
Set or clear the "read message" flag.

param
isRead true if the message has been read; false if not

        mIsRead = isRead;
    
public voidsetSubId(int subId)
set Subscription information

hide


             
        
        mSubId = subId;
    
public voidwriteToParcel(android.os.Parcel out, int flags)

        mSmsCbMessage.writeToParcel(out, flags);
        out.writeLong(mDeliveryTime);
        out.writeInt(mIsRead ? 1 : 0);