https://github.com/ulbora/nativescript-hosted-device
A Nativescript Plugin to access device information from a hosted Angular 2 application
https://github.com/ulbora/nativescript-hosted-device
Last synced: about 1 month ago
JSON representation
A Nativescript Plugin to access device information from a hosted Angular 2 application
- Host: GitHub
- URL: https://github.com/ulbora/nativescript-hosted-device
- Owner: Ulbora
- License: mit
- Created: 2016-05-31T00:36:07.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-05-31T01:27:07.000Z (almost 9 years ago)
- Last Synced: 2025-02-26T22:18:50.188Z (2 months ago)
- Language: JavaScript
- Size: 11.7 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Nativescript Hosted Device Plugin
This a Nativescript Plugin that lets you access device information from a hosted Angular 2 application.## Installation
```
tns plugin add nativescript-hosted-device```
## Usage
Create a wrapper application with the following code and a Navivescript WebView.
See the following project as an example:
https://github.com/Ulbora/NSWrapper```
var application = require("application");
function pageLoaded(args) {
var page = args.object;
var web = page.getViewById("webView");
var androidSettings = web.android.getSettings();
androidSettings.setJavaScriptEnabled(true);
var device = new com.ulbora.device.Device;
web.android.addJavascriptInterface(device, 'NSDevice');
web.url = "http://someURLWhereAngular2AppIsHosted";
}
exports.pageLoaded = pageLoaded;```
Inside the Angular 2 hosted application, write the code where you want to access device information.
See the following project as an example:
https://github.com/KenWilliamson/Angular2HostedMobileAppComponent code:
```
deviceReady: boolean;ngOnInit() {
this.id = this._routeParams.get('id');
this.hero = this._heroDetailsService.getHeroDetails(this.id);
try {
if (NSDevice) {
this.deviceReady = true;
}
} catch (err) {
}
}onShowDevice() {
try {
this.dev = "Mobile version: " + NSDevice.getModel();
} catch (err) {
alert('Failed because: ' + err);
this.error = err.message;
}
}```
Template Code:
```
Your device:```
## Available Methods
#### NSDevice.getModel()
Returns build information about the device
#### NSDevice.getProductName()
Returns product name of the device
#### NSDevice.getManufacturer()
Returns manufacturer information for the device
#### NSDevice.getSerialNumber()
Returns serial number of the device
#### NSDevice.getOSVersion()
Returns OS version of the device
#### NSDevice.getPlatform()
Returns the device platform