Java Question AIDL issues

Johan Schoeman

Expert
Licensed User
Longtime User
The project that I am working on at present contains 3 x .aidl files:
1. IWoyouService.aidl
2. ICallback.aidl
3. TransBean.aidl

I have extracted the java code for (1) and (2) above and added it to my project so that I can compile it with SLC. But SLC does not recognise the following from the java code that has been extracted from the .aidl files:
B4X:
oneway void onRunResult(boolean isSuccess);

....and....
B4X:
void printerInit(in ICallback callback);

The problem lies with "oneway" and "in". How do I get around this when using SLC to compile the project with?

As far as (3) above is concerned:
1. The project already contains TransBean.java (with Java code) with package name
B4X:
package com.sunmi.trans;

The java code in TransBean.java is as follows:
B4X:
package com.sunmi.trans;

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

public class TransBean implements Parcelable {

    private byte type = 0;
    private String text = "";
    private byte[] data = null;
    private int datalength = 0;
   
    public TransBean(){
        type = 0;
        data = null;
        text = "";
        datalength = 0;       
    };
   
    public byte getType() {
        return type;
    }

    public void setType(byte type) {
        this.type = type;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public byte[] getData() {
        return data;
    }

    public void setData(byte[] data) {
        if(data != null){
            datalength = data.length;
            this.data = new byte[datalength];
            System.arraycopy(data, 0, this.data, 0, datalength);
        }
    }

    public TransBean(Parcel source){
        this.type = source.readByte();
        this.datalength = source.readInt();
        this.text = source.readString();
        if(datalength > 0){
            this.data = new byte[datalength];
            source.readByteArray(data);
        }
    }
   
    public TransBean(byte type, String text, byte[] data){
        this.type = type;
        this.text = text;
        if(data != null){
            this.datalength = data.length;
            this.data = new byte[datalength];
            System.arraycopy(data, 0, this.data, 0, datalength);
        }
    }
   
    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByte(type);
        dest.writeInt(datalength);
        dest.writeString(text);
        if(data != null){
            dest.writeByteArray(data);
        }
    }
   
    public static Creator<TransBean> CREATOR = new Creator<TransBean>(){

        @Override
        public TransBean createFromParcel(Parcel source) {
            return new TransBean(source);
        }

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

}

But when extracting the java code for TransBean.aidl I get the following:
B4X:
package com.sunmi.trans;

parcelable TransBean;

The package name of the Java code extracted from the .aidl file is the same as that of the existing java class that already contains Java code.

How do I handle the two different java classes with the same class name and same package but with different java code in them?

A little bit snookered with these two problems at the moment. Anyone with some suggestions? Will be much appreciated!

For what it might be worth:
1. If I place the aidl folder that contains the aidl files under the src folder of the project and then import the project into Android Studio then there are no errors reported when looking at the java code of the aidl files. But when I add the extracted java code (classes) in the correct place in the folder structure of the project then even Android Studio has an issue with that.

upload_2017-11-4_11-52-0.png
 
Top