语言

Menu
Sites
Language
Programmatically Transfer File Android to Gear 2

Please could you provide a simple sample application or code which demonstrates sending a large file (e.g. PNG file) from the Android side AccessoryProviderService to the Tizen Wearable Gear 2's canvas for display?

So far I have been able to use BASE64 encoded string of data and reconstruct it on the Gear 2 canvas, but it fails when the file is larger than 1MB due to a size restriction on SASocket.send(bytes)

查看选择的答案

响应

7 回复
Thijs Mergaert

Hi Ashley,

Although I don't have a code example at hand right now, I'd suggest you take a look at http://img-developer.samsung.com/onlinedocs/sms/index.html, specifically at the SAft, SAFileTransfer and SAFileTransfer.EventListener classes.

Another option is to split up your BASE64 encoded string in chunks, send each chunk separately, and then reconstruct the image on the receiver side.

Sincerely yours,

Thijs

Ashley Hill

Thijs,

Thank you for your kind reply. I have a grasp of the SaFileTransfer from the sample, but I cannot find any documentation for the Wearable side i.e. sap.js please could you kindly try and publish a sample application for this.

Thanks
Ashley

Mark as answer
Thijs Mergaert
// I've skipped the definition of the onsuccess and onerror callbacks here
var agent = webapis.sa.requestSAAgent(onsuccess, onerror);
var filetransfer = agent.getSAFileTransfer();

var newFilePath = "file:///opt/usr/media/Downloads/ReceivedImage.jpg";

 var callback = {
     onreceive : function(transferId, fileName){
         try {
             filetransfer.receiveFile(transferId, newFilePath);
         } catch(e) {
             console.log("Error Exception, error name : " + e.name + ", error message : " + e.message);
         }
     },
     onprogress : function(transferId, progress){
         console.log("onprogress transferId : " + transferId + ", progress : " + progress);
     },
     oncomplete : function(transferId, localPath){
         console.log("File transfer complete.  transferId : " + transferId);
     },
     onerror : function(errorCode, transferId){
         console.log("FileReceiveError  transferId : " + transferId + " code : " + errorCode);
     }
 };

 try {
     filetransfer.setFileReceiveListener(callback);
 } catch(e) {
     console.log("Error Exception, error name : " + e.name + ", error message : " + e.message);
 }

The above is from the Help Contents in the Wearable SDK IDE.  Hope that helps.

Ashley Hill

I will test this as soon as possible, I couldn't find it in the documentation, but it looks like what I needed. Thank you very much indeed.

sunil sunny

Thanks for this piece of code I really needed it .....

AVSukhov

Hello,

See "Samples" in http://developer.samsung.com/samsung-gear#gLink_Download

Ashley Hill

The File Transfer sample seems to only transfer files from Gear to Android. The Gallery app does a lot more but the code is difficult to follow.