Languages

Menu
Sites
Language
BluetoothAdapter 의 getDevice 메소드 관련문의

https://developer.tizen.org/development/api-references/web-application?redirect=https://developer.tizen.org/dev-guide/2.3.1/org.tizen.web.apireference/html/device_api/wearable/tizen/bluetooth.html#BluetoothAdapter::getDevice

 

해당링크의 api 문서를 보면

 

void getDevice (BluetoothAddress address, BluetoothDeviceSuccessCallback successCallback, optional ErrorCallback? errorCallback)

 

라고 적혀있는고

예제를 보면 

adapter.getDevice("35:F4:59:D1:7A:03", gotDeviceInfo, onError);

블루투스에 연결된 디바이스의 맥주소를 입력하는 것으로 보입니다.

 

그런데 현재 블루투스로 연결된 디바이스의 맥주소는 어떻게 알아야 하나요?

setPowered 메소드로 알아야하나요?

 

 

 

Responses

1 Replies
Iqbal Hossain

Hello

You can get the Address of devices like this way,

main.js

( function () {
    
	
	var adapter = tizen.bluetooth.getDefaultAdapter();
	
	var discoverDevicesSuccessCallback =
	{

	   ondevicefound: function(device)
	   {
	   	  console.log("Found device - name: " + device.name+ "Address: "+device.address);
	   }
	};

	adapter.discoverDevices(discoverDevicesSuccessCallback, null);
	
	window.addEventListener( 'tizenhwkey', function( ev ) {
		if( ev.keyName === "back" ) {
			var page = document.getElementsByClassName( 'ui-page-active' )[0],
				pageid = page ? page.id : "";
			if( pageid === "main" ) {
				try {
					tizen.application.getCurrentApplication().exit();
				} catch (ignore) {
				}
			} else {
				window.history.back();
			}
		}
	} );
	
} () );

In html nothing but basic structure,

<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="width=device-width,user-scalable=no"/>
	<script src="./lib/jquery.js"></script>
	<script type="text/javascript" src="./lib/tau/mobile/js/tau.js" data-build-remove="false"></script>
	<link rel="stylesheet"  href="./lib/tau/mobile/theme/default/tau.css">

	<script src="./js/main.js"></script>

	<title>BT Basic</title>
	<link rel="stylesheet" type="text/css" href="./css/style.css"/>
</head>

<body>
    <div class="ui-page ui-page-active" id="main">
		<header class="ui-header">
			<h2 class="ui-title">BT Basic</h2>
		</header>
		<div class="ui-content content-padding">
			
		</div>
	</div>
</body>
</html>
Don't forget to add these privilege
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns:tizen="http://tizen.org/ns/widgets" xmlns="http://www.w3.org/ns/widgets" id="http://yourdomain/BasicBT" version="1.0.0" viewmodes="maximized">
    <tizen:application id="b2iTG9KHr7.BasicBT" package="b2iTG9KHr7" required_version="2.3.1"/>
    <content src="index.html"/>
    <feature name="http://tizen.org/feature/screen.size.all"/>
    <icon src="icon.png"/>
    <name>BasicBT</name>
    <tizen:privilege name="http://tizen.org/privilege/application.launch"/>
    <tizen:privilege name="http://tizen.org/privilege/bluetooth"/>
    <tizen:privilege name="http://tizen.org/privilege/bluetooth.admin"/>
    <tizen:privilege name="http://tizen.org/privilege/bluetooth.gap"/>
    <tizen:privilege name="http://tizen.org/privilege/bluetooth.spp"/>
    <tizen:profile name="mobile"/>
    <tizen:setting context-menu="disable"/>
</widget>

And here is demo,

 

For more study you can get help from this tutorial.

If you find my answer helpful, please mark as best answer.