mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 23:42:53 +08:00
84 lines
2.7 KiB
JavaScript
Executable File
84 lines
2.7 KiB
JavaScript
Executable File
/*
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
* or more contributor license agreements. See the NOTICE file
|
|
* distributed with this work for additional information
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
* to you 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.
|
|
*/
|
|
|
|
if (!Cordova.hasResource("device")) {
|
|
Cordova.addResource("device");
|
|
|
|
/**
|
|
* This represents the mobile device, and provides properties for inspecting the model, version, UUID of the
|
|
* phone, etc.
|
|
* @constructor
|
|
*/
|
|
var Device = function() {
|
|
this.available = Cordova.available;
|
|
this.platform = null;
|
|
this.version = null;
|
|
this.name = null;
|
|
this.uuid = null;
|
|
this.cordova = null;
|
|
|
|
var me = this;
|
|
this.getInfo(
|
|
function(info) {
|
|
me.available = true;
|
|
me.platform = info.platform;
|
|
me.version = info.version;
|
|
me.name = info.name;
|
|
me.uuid = info.uuid;
|
|
me.cordova = info.cordova;
|
|
Cordova.onCordovaInfoReady.fire();
|
|
},
|
|
function(e) {
|
|
me.available = false;
|
|
console.log("Error initializing Cordova: " + e);
|
|
alert("Error initializing Cordova: "+e);
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Get device info
|
|
*
|
|
* @param {Function} successCallback The function to call when the heading data is available
|
|
* @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL)
|
|
*/
|
|
Device.prototype.getInfo = function(successCallback, errorCallback) {
|
|
|
|
// successCallback required
|
|
if (typeof successCallback !== "function") {
|
|
console.log("Device Error: successCallback is not a function");
|
|
return;
|
|
}
|
|
|
|
// errorCallback optional
|
|
if (errorCallback && (typeof errorCallback !== "function")) {
|
|
console.log("Device Error: errorCallback is not a function");
|
|
return;
|
|
}
|
|
|
|
// Get info
|
|
Cordova.exec(successCallback, errorCallback, "Device", "getDeviceInfo", []);
|
|
};
|
|
|
|
Cordova.addConstructor(function() {
|
|
if (typeof navigator.device === "undefined") {
|
|
navigator.device = window.device = new Device();
|
|
}
|
|
});
|
|
}
|