https://github.com/ulbora/nativescript-hosted-toast
A Nativescript Plugin to access Android Toast on a device from a hosted Angular 2 application
https://github.com/ulbora/nativescript-hosted-toast
Last synced: about 1 month ago
JSON representation
A Nativescript Plugin to access Android Toast on a device from a hosted Angular 2 application
- Host: GitHub
- URL: https://github.com/ulbora/nativescript-hosted-toast
- Owner: Ulbora
- License: mit
- Created: 2016-05-31T00:39:04.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-05-31T01:49:39.000Z (almost 9 years ago)
- Last Synced: 2024-12-16T09:43:29.755Z (5 months ago)
- Language: JavaScript
- Size: 3.91 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 Toast Plugin
This a Nativescript Plugin that lets you make toast from a hosted Angular 2 application.## Installation
```
tns plugin add nativescript-hosted-toast```
## 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");
var context = application.android.context;
function pageLoaded(args) {
var page = args.object;
var web = page.getViewById("webView");
var androidSettings = web.android.getSettings();
androidSettings.setJavaScriptEnabled(true);
var hostedToast = new com.ulbora.hosted.toast.HostedToast(context);
web.android.addJavascriptInterface(hostedToast, 'HostedToast');
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() {
try {
if (HostedToast) {
this.deviceReady = true;
}
} catch (err) {
}
}showToast() {
try {
HostedToast.showToast("Toast is working in a hosted world.");
} catch (err) {
}
}```
Template Code:
```
Your Toast:```
## Available Methods
#### HostedToast.showToast("some message")
Sends a toast message to the device