Android SDK for NFC-Powered e-Paper

From Waveshare Wiki
Jump to: navigation, search

For easily develop your own APP, we provided the SDK, the SDK packages the send function, you only need to use it for updating the NFC-Powered e-Paper.

Import the .jar file

  • Download the SDK
    • Download the SDK and unzip it to get the .jar file
    • NFC SDK
  • Copy the Jar file to libs directory of your project.
NFC-SDK-1.png
  • Find the .jar file in your project, right-click it to add it as libraries.
NFC-SDK-2.png NFC-SDK-3.png NFC-SDK-4.png
  • After adding, the line will bee auto-added to build.gradle.:
NFC-SDK-5.png

Use guide

There are two functions provided, one is send function and any is status function.

Sent function

  • int a(NfcA var1, int var2, Bitmap var3) ;
    • var1: NFC tag
    • var2:Type of the e-Paper (refer to the type table below)
    • var3: The BMP picture for updating.(refer to the picture table below)
  • Return
    • 1:Sent successfully
    • 0:Failed
Type
Type e-Paper
1 2.13inch
2 2.9inch
3 4.2inch
4 7.5inch
5 7.5inch HD
6 2.7inch
7 2.9inch B
Pictures
Type e-Paper width height
1 2.13inch 250 122
2 2.9inch 296 128
3 4.2inch 400 300
4 7.5inch 800 480
5 7.5inch HD 880 528
6 2.7inch 264 176
7 2.9inch B 296 128
Bitmap

Black/White e-Paper: Requrie BMP pictures, which has only Black and white pixels.
Three-color e-Paper: Require BMP picture, which has only three colors.

Status function

  • int b()
  • Return:
    • 0-100:The current process of sending.
    • -1:Failed

Examples

protected void onNewIntent(Intent intent) {//Recognized the NFC
    if (mWriteMode && NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
        detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        String[] tech = detectedTag.getTechList();//Get the descriptor
        if(tech[0].equals("android.nfc.tech.NfcA")) {//if the descriptor is correct
            Thread t = new Thread() {//Create an new thread
                @Override
                public void run() {
                    Boolean success = false;
                    NfcA tntag;//NFC tag

                    final a  a = new a();//Create a new instance.
                    a.a();//初始化发送函数

                    Thread thread = new Thread(new Runnable() {//Create thread
                        @Override
                        public void run() {
                            EPD_total_progress = 0;
                            while(EPD_total_progress != -1){
                                EPD_total_progress = a.b();//Read the process
                                if(EPD_total_progress == -1){
                                    break;
                                }
                                setStatusBody(getString(R.string.txing) + EPD_total_progress +"%");
                                if(EPD_total_progress == 100 ){
                                    break;
                                }
                                SystemClock.sleep(10);
                            }
                        }
                    });
                    thread.start();//start the thread
                    tntag = NfcA.get(detectedTag);//Get the tag instance.
                    try {
                        int whether_succeed = a.a(tntag,Size_Flag, bmp_send);//Send picture
                        if(whether_succeed == 1){
                            success = true; 

                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    checkNFCpopwindow.dismiss(); //Tips

                                }
                            });
                            Success_Sound_Effects();

                        }else{
                            setStatusBody(getString(R.string.txfail));
                        }

                    } finally { 
                        try {
                            if (success == false) {
                                setStatusBody(getString(R.string.txfail));
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        checkNFCpopwindow.dismiss();
                                    }
                                });
                            }
                            tntag.close();
                        } catch (IOException e) {//handle exception error
                            e.printStackTrace();
                        }
                    }
                }
            };
            t.start();//Start thread
        }
    }
}