2015-12-04 58 views
1

到目前爲止我的代碼從URL中byte []數組獲取Android的二進制數據(Flatbuffers)

Globals.GET(Globals.GET_WORDS_URL, new Globals.VolleyCallback() { 

     @Override 
     public void onSuccess(String result) { 
      byte[] bytes = result.getBytes(); 
      loadFlatBuffer(bytes); 
     } 

     @Override 
     public void onFail(String result) { 

     } 
    }); 

我得到它的字符串,然後將其轉換成字節數組。

我想

我想什麼它的byte []數組代替

它是一個.bin文件得到儘可能字節從URL

回答

2

如果您使用Volley,根據您的要求,我建議您創建一個自定義請求,如下所示

public class BinaryRequest extends Request<byte[]> 

您可以在

Google's training documentation - Implementing a Custom Request

然後你的應用程序中找到有關創建自定義要求的詳細信息,請使用如下所示:

BinaryRequest binaryRequest = new BinaryRequest(method, url, new Response.Listener<byte[]>() { 
      @Override 
      public void onResponse(byte[] response) { 
       //do something... 
      } 
     }, new Response.ErrorListener() { 
      @Override 
      public void onErrorResponse(VolleyError error) { 
       //do something... 
      } 
    }); 

希望這有助於!

+0

什麼是第一個參數「方法」? – johnrao07

+0

這是一個整數,0是GET,1是POST :) – BNK

+0

你可以參考我的BinaryRequest.java的源代碼https://drive.google.com/file/d/0B7ivmSFu7UqZSVlVbXFBdWpNdjA/view?usp=sharing – BNK