An open API service indexing awesome lists of open source software.

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

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/Angular2HostedMobileApp

Component 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