Kelderic
Kelderic

Reputation: 6697

is it Possible to Trigger Android Toast Notification from Webpage?

Right now in web pages I sometimes want to send an alert to the user, saying that an Ajax request was successful or unsucessful. Using Javascript's alert() function works, but on Android it's a large popup that the user has to interact with before continuing.

Some apps trigger a different sort of message. It's a gray rectangle with rounded corners. It appears near the bottom of the screen and is unobtrusive but noticeable.

enter image description here

Is there a way to trigger this from Javascript?

Edit: I'm running a website, not an HTML5 app, and I don't need the undo functionality, just the messaging.

Upvotes: 3

Views: 2323

Answers (2)

Varun Verma
Varun Verma

Reputation: 693

You can achieve this by using JavascriptInterface callback in your android code.

This allows you to call android function using javascript, where you can call the function to display your toast.

See this documentation.

Upvotes: 1

Shalom Aleichem
Shalom Aleichem

Reputation: 3027

It depends on whether you're running a JavaScript/HTML5 app that uses WebView on your android device or if it is just a website.

If it is the first case, then there is a way to show native Android toast notification using Android JavaScript interface. This exact problem is solved here in Android WebView documentation.

In case you're running a website and you want it to look native on android, you will have to implement a notification on your own and style it so that it looks similar to native toast notification. You can use jQuery UI tooltip with custom styling for that purpose, for example.

Upvotes: 5

Related Questions