forked from phonegap/phonegap-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
836 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* Copyright (c) 2011 - Andago | ||
* | ||
* author: Daniel Tizon | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
cordova.define("cordova/plugin/bluetooth", | ||
function(require, exports, module) { | ||
var exec = require("cordova/exec"); | ||
|
||
var Bluetooth = function() {}; | ||
|
||
/** | ||
* @param argument Argument that we are going to pass to the plugin - for this method no arguments are needed | ||
* @param successCallback The callback which will be called when listDevices is successful | ||
* @param failureCallback The callback which will be called when listDevices encouters an error | ||
*/ | ||
Bluetooth.prototype.listDevices = function(argument,successCallback, failureCallback) { | ||
exec(successCallback, failureCallback, 'BluetoothPlugin', 'listDevices', [argument]); | ||
}; | ||
|
||
/** | ||
* @param argument Argument that we are going to pass to the plugin - for this method no arguments are needed | ||
* @param successCallback The callback which will be called when listDevices is successful | ||
* @param failureCallback The callback which will be called when listDevices encouters an error | ||
*/ | ||
Bluetooth.prototype.isBTEnabled = function(argument,successCallback, failureCallback) { | ||
exec(successCallback, failureCallback, 'BluetoothPlugin', 'isBTEnabled', [argument]); | ||
}; | ||
|
||
/** | ||
* @param argument Argument that we are going to pass to the plugin - for this method no arguments are needed | ||
* @param successCallback The callback which will be called when listDevices is successful | ||
* @param failureCallback The callback which will be called when listDevices encouters an error | ||
*/ | ||
Bluetooth.prototype.enableBT = function(argument,successCallback, failureCallback) { | ||
exec(successCallback, failureCallback, 'BluetoothPlugin', 'enableBT', [argument]); | ||
}; | ||
|
||
/** | ||
* @param argument Argument that we are going to pass to the plugin - for this method no arguments are needed | ||
* @param successCallback The callback which will be called when listDevices is successful | ||
* @param failureCallback The callback which will be called when listDevices encouters an error | ||
*/ | ||
Bluetooth.prototype.disableBT = function(argument,successCallback, failureCallback) { | ||
exec(successCallback, failureCallback, 'BluetoothPlugin', 'disableBT', [argument]); | ||
}; | ||
|
||
/** | ||
* @param argument Argument that we are going to pass to the plugin, you need pass the MAC address of the bluetooth device with wich you want to pair | ||
* @param successCallback The callback which will be called when listDevices is successful | ||
* @param failureCallback The callback which will be called when listDevices encouters an error | ||
*/ | ||
Bluetooth.prototype.pairBT = function(argument,successCallback, failureCallback) { | ||
exec(successCallback, failureCallback, 'BluetoothPlugin', 'pairBT', [argument]); | ||
}; | ||
|
||
/** | ||
* @param argument Argument that we are going to pass to the plugin, you need pass the MAC address of the bluetooth device that you want unpair | ||
* @param successCallback The callback which will be called when listDevices is successful | ||
* @param failureCallback The callback which will be called when listDevices encouters an error | ||
*/ | ||
Bluetooth.prototype.unPairBT = function(argument,successCallback, failureCallback) { | ||
exec(successCallback, failureCallback, 'BluetoothPlugin', 'unPairBT', [argument]); | ||
}; | ||
|
||
/** | ||
* @param argument Argument that we are going to pass to the plugin - for this method no arguments are needed | ||
* @param successCallback The callback which will be called when listDevices is successful | ||
* @param failureCallback The callback which will be called when listDevices encouters an error | ||
*/ | ||
Bluetooth.prototype.listBoundDevices = function(argument,successCallback, failureCallback) { | ||
exec(successCallback, failureCallback, 'BluetoothPlugin', 'listBoundDevices', [argument]); | ||
}; | ||
|
||
/** | ||
* @param argument Argument that we are going to pass to the plugin - for this method no arguments are needed | ||
* @param successCallback The callback which will be called when listDevices is successful | ||
* @param failureCallback The callback which will be called when listDevices encouters an error | ||
*/ | ||
Bluetooth.prototype.stopDiscovering = function(argument,successCallback, failureCallback) { | ||
exec(successCallback, failureCallback, 'BluetoothPlugin', 'stopDiscovering', [argument]); | ||
}; | ||
|
||
/** | ||
* @param argument Argument that we are going to pass to the plugin, you need pass the MAC address of the mobile that you want to know if it is bound | ||
* @param successCallback The callback which will be called when listDevices is successful | ||
* @param failureCallback The callback which will be called when listDevices encouters an error | ||
*/ | ||
Bluetooth.prototype.isBound = function(argument,successCallback, failureCallback) { | ||
exec(successCallback, failureCallback, 'BluetoothPlugin', 'isBound', [argument]); | ||
}; | ||
|
||
var bluetooth = new Bluetooth(); | ||
module.exports = bluetooth; | ||
}); | ||
|
||
|
||
if (!window.plugins) { | ||
window.plugins = {}; | ||
} | ||
if (!window.plugins.bluetooth) { | ||
window.plugins.bluetooth = cordova.require("cordova/plugin/bluetooth"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,256 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<title>PhoneGap</title> | ||
<script type="text/javascript" charset="utf-8" src="cordova-2.5.0.js"></script> | ||
<script type="text/javascript" charset="utf-8" src="bluetooth.js"></script> | ||
|
||
|
||
<script type="text/javascript" charset="utf-8"> | ||
|
||
|
||
function onBodyLoad() | ||
{ | ||
document.addEventListener("deviceready",onDeviceReady,false); | ||
} | ||
|
||
|
||
|
||
function onDeviceReady() | ||
{ | ||
|
||
|
||
//------------------------------------------------------ listDevices example ------------------------------------------------------ | ||
|
||
var btnListDevices = document.getElementById("list-devices"); | ||
btnListDevices.onclick = function() { | ||
window.plugins.bluetooth.listDevices(null, | ||
function(r){printResult(r)}, | ||
function(e){log(e)} | ||
); | ||
} | ||
|
||
|
||
//------------------------------------------------------ isBTEnabled example ------------------------------------------------------ | ||
|
||
var btnIsBTEnabled = document.getElementById("isBTEnabled"); | ||
btnIsBTEnabled.onclick = function() { | ||
|
||
window.plugins.bluetooth.isBTEnabled(null, | ||
function(r){printResult2(r)}, | ||
function(e){log(e)} | ||
); | ||
} | ||
|
||
|
||
|
||
|
||
//------------------------------------------------------ enableBT example ------------------------------------------------------ | ||
|
||
var btnEnableBT = document.getElementById("enableBT"); | ||
btnEnableBT.onclick = function() { | ||
|
||
window.plugins.bluetooth.enableBT(null, | ||
function(r){printResult3(r)}, | ||
function(e){log(e)} | ||
); | ||
} | ||
|
||
|
||
|
||
//------------------------------------------------------ disableBT example ------------------------------------------------------ | ||
|
||
var btnDisableBT = document.getElementById("disableBT"); | ||
btnDisableBT.onclick = function() { | ||
|
||
window.plugins.bluetooth.disableBT(null, | ||
function(r){printResult4(r)}, | ||
function(e){log(e)} | ||
); | ||
} | ||
|
||
|
||
|
||
|
||
//------------------------------------------------------ pairBT example ------------------------------------------------------ | ||
|
||
var btnPairBT = document.getElementById("pairBT"); | ||
btnPairBT.onclick = function() { | ||
|
||
window.plugins.bluetooth.pairBT("6C:9B:02:44:FA:BF", | ||
function(r){printResult5(r)}, | ||
function(e){log(e)} | ||
); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
//------------------------------------------------------ unPairBT example ------------------------------------------------------ | ||
|
||
var btnUnPairBT = document.getElementById("unPairBT"); | ||
btnUnPairBT.onclick = function() { | ||
|
||
window.plugins.bluetooth.unPairBT("6C:9B:02:44:FA:BF", | ||
function(r){printResult6(r)}, | ||
function(e){log(e)} | ||
); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
//------------------------------------------------------ listBoundDevices example ------------------------------------------------------ | ||
|
||
var btnListBoundDevices = document.getElementById("list-bound-devices"); | ||
btnListBoundDevices.onclick = function() { | ||
|
||
window.plugins.bluetooth.listBoundDevices(null, | ||
function(r){printResult7(r)}, | ||
function(e){log(e)} | ||
); | ||
} | ||
|
||
|
||
|
||
|
||
//------------------------------------------------------ stopDiscovering example ------------------------------------------------------ | ||
|
||
var btnStopDiscovering = document.getElementById("stopDiscovering"); | ||
btnStopDiscovering.onclick = function() { | ||
|
||
window.plugins.bluetooth.stopDiscovering(null, | ||
function(r){printResult8(r)}, | ||
function(e){log(e)} | ||
); | ||
} | ||
|
||
|
||
|
||
|
||
//------------------------------------------------------ isBound example ------------------------------------------------------ | ||
|
||
var btnIsBound = document.getElementById("isBound"); | ||
btnIsBound.onclick = function() { | ||
|
||
window.plugins.bluetooth.isBound("6C:9B:02:44:FA:BF", | ||
function(r){printResult9(r)}, | ||
function(e){log(e)} | ||
); | ||
} | ||
} | ||
|
||
|
||
function printResult(resultadoString){ | ||
var htmlText =""; | ||
var i=0; | ||
|
||
var resultado = eval(resultadoString); | ||
|
||
for(i=0;i<resultado.length;i++) | ||
{ | ||
htmlText=htmlText+"<ul><li>Name Device: "+resultado[i].name+"</li></ul>"; | ||
htmlText=htmlText+"<ul><li>Address Device: "+resultado[i].address+"</li></ul>"; | ||
} | ||
document.getElementById("result").innerHTML=htmlText; | ||
} | ||
|
||
|
||
|
||
function printResult2(resultado){ | ||
|
||
var htmlText="<ul><li>is Bluetooth Enabled?: "+resultado+"</li></ul>"; | ||
document.getElementById("result").innerHTML=htmlText; | ||
} | ||
|
||
|
||
|
||
function printResult3(resultado){ | ||
|
||
var htmlText="<ul><li>Bluetooth Enabled?: "+resultado+"</li></ul>"; | ||
document.getElementById("result").innerHTML=htmlText; | ||
} | ||
|
||
|
||
|
||
|
||
function printResult4(resultado){ | ||
|
||
var htmlText="<ul><li>Bluetooth Disabled?: "+resultado+"</li></ul>"; | ||
document.getElementById("result").innerHTML=htmlText; | ||
} | ||
|
||
|
||
|
||
function printResult5(resultado){ | ||
|
||
var htmlText="<ul><li>Pairing with Bluetooth Device: "+resultado+"</li></ul>"; | ||
document.getElementById("result").innerHTML=htmlText; | ||
} | ||
|
||
|
||
|
||
function printResult6(resultado){ | ||
|
||
var htmlText="<ul><li>unPairing Bluetooth Device: "+resultado+"</li></ul>"; | ||
document.getElementById("result").innerHTML=htmlText; | ||
} | ||
|
||
|
||
|
||
function printResult7(resultadoString){ | ||
var htmlText =""; | ||
var i=0; | ||
|
||
var resultado = eval(resultadoString); | ||
|
||
for(i=0;i<resultado.length;i++) | ||
{ | ||
htmlText=htmlText+"<ul><li>Name Device: "+resultado[i].name+"</li></ul>"; | ||
htmlText=htmlText+"<ul><li>Address Device: "+resultado[i].address+"</li></ul>"; | ||
} | ||
document.getElementById("result").innerHTML=htmlText; | ||
} | ||
|
||
|
||
|
||
function printResult8(resultado){ | ||
|
||
var htmlText="<ul><li>Stopping Discovering Bluetooth Devices: "+resultado+"</li></ul>"; | ||
document.getElementById("result").innerHTML=htmlText; | ||
} | ||
|
||
|
||
|
||
function printResult9(resultado){ | ||
|
||
var htmlText="<ul><li>is Device bound with mobile address 6C:9B:02:44:FA:BF?: "+resultado+"</li></ul>"; | ||
document.getElementById("result").innerHTML=htmlText; | ||
} | ||
|
||
</script> | ||
</head> | ||
|
||
|
||
<body onload="onBodyLoad()"> | ||
<input id="isBTEnabled" type="button" value="Is Bluetooth Enabled?" /> | ||
<input id="enableBT" type="button" value="Enable Bluetooth" /> | ||
<input id="disableBT" type="button" value="Disable Bluetooth" /> | ||
<input id="list-devices" type="button" value="List Bluetooth Devices" /> | ||
<input id="list-bound-devices" type="button" value="List Bluetooth Bound Devices" /> | ||
<input id="pairBT" type="button" value="Pair Device" /> | ||
<input id="unPairBT" type="button" value="Unpair Device" /> | ||
<input id="stopDiscovering" type="button" value="Stop Discovering" /> | ||
<input id="isBound" type="button" value="Is Device bound with mobile" /> | ||
|
||
<hr> | ||
|
||
<div id="result"></div> | ||
|
||
<hr> | ||
|
||
|
||
</body> | ||
</html> |
13 changes: 13 additions & 0 deletions
13
Android/Bluetooth/2.2.0/src/com/phonegap/plugins/bluetooth/Bluetooth.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.phonegap.plugin.bluetooth; | ||
|
||
import org.apache.cordova.DroidGap; | ||
import android.os.Bundle; | ||
|
||
public class Bluetooth extends DroidGap { | ||
/** Called when the activity is first created. */ | ||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
super.loadUrl("file:///android_asset/www/index.html"); | ||
} | ||
} |
Oops, something went wrong.