Languages

Menu
Sites
Language
Sending file from Gear to Smartphone

Hello,

I would like to ask if it's possible to send file from Gear2 to smartphone? (I know that it is possible from smartphone to Gear2 but is there any code to do it to the other direction).

Thanks in advance.

Responses

12 Replies
Marco Buettner

Imo the gear API supports "sendFile"

AVSukhov

Hello,

You can find example in 

http://developer.samsung.com/samsung-gear

in Download -> Samples -> File Transfer

karray gargouri

Thank you,

As i said before (I know that it is possible from smartphone to Gear2), so is there any tutorial or a sample code to perform a file/picture transfer from the smartphone to the gear?

 

Marco Buettner

The usage is the same like on "sendData"-API of Wearable SDK... So look in the SDK Documentation of Tizen SDK for Wearables for "sendFile" you will find a example for usage in the API description.

sunil sunny

http://img-developer.samsung.com/contents/cmm/SamsungGearApplication_HelloAccessory_DevelopersGuide_1.15.pdf

 

Page 32 gives an example, try to implement that. I already tried it and I was able to recieve image files and sound files from the phone to gear.

karray gargouri

I found  a method on the Android side:

mSAFileTransfer.send(peerAgent, filename)

my question here is that what is the type of the "peerAgent" object? how could I instanciate it?

Thanks

 

flopo lopolus

the peer agent is the device that is available that is connected via bluetooth to your samsung phone. you can find peer agents by calling super.findPeerAgents(); in your class that extends SAAgent. If a peerAgent is found the Overrided callback: protected void onFindPeerAgentResponse(SAPeerAgent peerAgent, int result)  is called which will give you the peerAgent of the device you want to send to.

flopo lopolus

sorry left this part out. when you want to connect o your samsung gear device you also need to request a connection when you find your peer agent. my overriden onPeerAgentResponse looks like this:

 

 protected void onFindPeerAgentResponse(SAPeerAgent peerAgent, int result) {

        if(peerAgent != null){
                 requestServiceConnection(peerAgent);}
        else
            Log.e("onFindPeerAgentResponse", "Peer not found");

    }

 

 

after this you need to go into your tizen ide and edit your javascript to actually accept incoming connections. if you  are working off the FTSample application,

open the sap.js file and add the onrequest: function to your gAgent.setServiceConnectionListener like this:

 

gAgent.setServiceConnectionListener({
    		
			onrequest : function(peerAgent){
				gPeerAgent = peerAgent;
				console.log("heddo");
				gAgent.acceptServiceConnectionRequest(peerAgent);
			},
			
		    onconnect : function(sock) {
			    console.log('onconnect');

			    gSocket = sock;
			    gSocket.setDataReceiveListener(function(channel, respDataJSON) {
				    console.log('message received : ' + respDataJSON);

				    stringCommand(respDataJSON);

 

onrequest is called when your android phone sends the request and acceptServiceConnectionRequest() accepts the connection from the peerAgent.

 

 



 

karray gargouri

I tried to implement it as I showed in my last post, but it didn't work.... Am I doing right?

Marco Buettner

Objet?

karray gargouri

Well, I tried with this code and I don't know if I am doing it correctly:

main.js

var newFilePath = "file:///opt/usr/media/Downloads/map.png";
var transferId = null;
var filetransfer = null;


function toastAlert(msg) {
    $('#popupToastMsg').empty();
	$('#popupToastMsg').append(msg);
	gear.ui.openPopup($('#popupToast'));
	console.log(msg);
}

function showSendPage() {
	$('#main').hide();
	$('#sendPage').show();
	$('#sendprogress').attr('value', 0);
}

function showMain(message) {
	$('#sendPage').hide();
	$('#main').show();
	if (message != undefined) {
		toastAlert(message);
	}
	gTransferId = 0;
}


var receivefilecallback = 
{
   onreceive: function(transferId, fileName)
   { 
	   try {
		   gFileTransfer.receiveFile(transferId, newFilePath);
		   } catch(e) {
		   console.log("Error Exception, error name : " + e.name + ", error message : " + e.message);
		   }
         console.log("Incoming file transfer request form the remote peer agent."+ 
                  transferId: " + transferId + " fileName : " + fileName); 
   },
   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 = agent.getSAFileTransfer();
filetransfer.setFileReceiveListener(receivefilecallback);
// agent.setPeerAgentFindListener(peeragentfindcallback);
// agent.findPeerAgents();
} catch (err) {
console.log('getSAFileTransfer exception <' + err.name + '> : ' + err.message);

}


function initialize() {
alert("debut init");
	var receivefilecallback = 
	{
	   onreceive: function(transferId, fileName)
	   { 
		   try {
			   gFileTransfer.receiveFile(transferId, newFilePath);
			   } catch(e) {
			   console.log("Error Exception, error name : " + e.name + ", error message : " + e.message);
			   }
	         console.log("Incoming file transfer request form the remote peer agent."+ 
	                  transferId: " + transferId + " fileName : " + fileName); 
	   },
	   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{
		alert("Into initialize");
	filetransfer = agent.getSAFileTransfer();
	filetransfer.setFileReceiveListener(receivefilecallback);
	
	} catch (err) {
	console.log('getSAFileTransfer exception <' + err.name + '> : ' + err.message);

	}
	
	
	sapInit(function() {
		console.log('Succeed to connect');
		ftInit(successCb, function(err) {
			toastAlert('Failed to get File Transfer');
		});
	}, function(err) {
		toastAlert('Failed to connect to service');
	});
}

(function(ui) {
	var closePopup = ui.closePopup.bind(ui);
	var toastPopup = document.getElementById('popupToast');
	toastPopup.addEventListener('popupshow', function(ev){
		setTimeout(closePopup, 3000);
	}, false);
})(window.gear.ui);

and for the index.html:

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width,user-scalable=no"/>
	<title>Gear UI</title>
	<link rel="stylesheet"  href="lib/gear-ui/themes/default/gear.ui.min.css">
	<!-- load theme file for your application -->
	<link rel="stylesheet"  href="css/style.css">
</head>
<body>
	<div class="ui-page ui-page-active" id="main">
		<header class="ui-header">
			<h2 class="ui-title">FTSampleConsumer</h2>
		</header>
		<div class="ui-content">
			<input type="button" class="ui-btn ui-inline" value="Connect" onclick="initialize();" style="width:100%;"/>
			<div style="overflow-y:scroll; -webkit-overfolw-scrolling:touch; height:70%;">
				<ul class="ui-listview">
				</ul>
			</div>
		</div>
	</div>
	<div class="ui-page" id="sendPage">
		<header class="ui-header">
			<h2 class="ui-title">Send file ... </h2>
		</header>
		<div class="ui-content">
		<progress id="sendprogress" class="ui-progress-indeterminate" max="100" value="0"></progress>
        <input type="button" class="ui-btn ui-inline" value="Cancel" onclick="cancelFile();"/>
    </div>
    </div>
    <div id="popupToast" class="ui-popup ui-popup-toast">
    	<div id="popupToastMsg" class="ui-popup-content" style="overflow-y:scroll;">
    	</div>
    </div>
</body>
<script type="text/javascript" src="lib/gear-ui/js/gear.ui.min.js"></script>
<!-- load javascript file for your application -->
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="js/sap.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</html>

The problem is that the initialize method  is not even executed! (none of the alerts is shown).
What's wrong with my code?should I remove some lines?

 

Thanks in advance!

Amanda Powell

I find this post very intersting. The long wait is over for smartphone lovers since iPhone 6 and now, iPhone 6 Plus is already out in the market. When Apple's introduced its two newest marquee handsets, the most readily discernible difference between the iPhone 6 and iPhone 6 Plus was their sizes. It’s one continuous formwhere hardware and software function in perfect unison, creating a new generation of iPhone that’s better by any measure. Thanks a lot to our fast-innovating technology for all the convenience we can enjoy with our gadgets.