Android Aidl枚举无法构建

时间:2018-08-24 09:21:56

标签: android aidl

我正在尝试构建我的项目,但是Aidl文件总是有问题 这是我的Enum代码

package com.example.printer;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Printer command status
 */
public enum PrinterCommandStatus implements Parcelable {
    /**
     * successful result
     */
    SUCCESS(1),
    /**
     * general error
     */
    ERROR(-1),
    /**
     * out of paper
     */
    OUT_OF_PAPER(123),
    /**
     * internal printer error
     */
    INTERNAL_ERROR(121),
    /**
     * printer over temperature
     */
    OVER_TEMPERATURE(75),
    /**
     * printer jammed paper
     */
    PAPERJAM(70),
    /**
     * printer voltage error
     */
    VOLTAGE_ERROR(55);

    private final int statuscode;

    PrinterCommandStatus(int statuscode) {
        this.statuscode = statuscode;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(name());
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<PrinterCommandStatus> CREATOR = new Creator<PrinterCommandStatus>() {
        @Override
        public PrinterCommandStatus createFromParcel(Parcel in) {
            return PrinterCommandStatus.valueOf(in.readString());
        }

        @Override
        public PrinterCommandStatus[] newArray(int size) {
            return new PrinterCommandStatus[size];
        }
    };

    public int getStatuscode() {
        return statuscode;
    }

    public static PrinterCommandStatus getPrinterCommandStatusByCode(int statuscode) {
        PrinterCommandStatus printerCommandStatus = ERROR;

        for (PrinterCommandStatus status : PrinterCommandStatus.values()) {
            if (status.getStatuscode() == statuscode) {
                printerCommandStatus = status;
                break;
            }
        }

        return printerCommandStatus;
    }
}

这是我的助手

package com.example.printer;

import com.example.printer.PrinterCommandStatus;

interface IDirectPrintListener {

    void started( in String printId);

    void block( in String printId, in String reasonMessage, in com.example.printer.PrinterCommandStatus printerCommandStatus);

    void cancel( in String printId);

    void failed( in String printId, in String errorMessage, in com.example.printer.PrinterCommandStatus printerCommandStatus);

    void complete( in String printId);

}

当我使用 Parcelable 添加另一个类时,一切正常,但不适用于枚举,我做错了什么? 我正在尝试重建项目,但是没有用

将Aidl文件中的enum更改为String并强制转换为Enum并不是一个好方法,但是我没有找到有关如何使用enum进行纠正的说明

1 个答案:

答案 0 :(得分:0)

我发现了我的错误。我忘了用代码添加PrinterCommandStatus.aidl文件

package com.example.printer;

parcelable PrinterCommandStatus;