Package com.oorian.html.js.share
Class ShareApi
java.lang.Object
com.oorian.html.js.JavaScriptApi
com.oorian.html.js.share.ShareApi
Provides access to the Web Share API from server-side Java code.
The Web Share API allows sharing content (text, URLs, files) to native sharing targets such as other apps on the device. This API is primarily useful on mobile devices where native sharing dialogs are common.
Browser Support:
- Chrome for Android (full support)
- Safari on iOS (full support)
- Edge on Windows (limited support)
- Firefox (limited support)
Usage:
public class MyPage extends HtmlPage implements ShareListener
{
@Override
protected void createBody(Body body)
{
Button shareBtn = new Button("Share");
shareBtn.registerListener(this, MouseClickedEvent.class);
body.addElement(shareBtn);
}
@Override
public void onEvent(MouseClickedEvent event)
{
ShareApi.share(this, "Check this out!", "My App", "https://example.com");
}
@Override
public void onEvent(ShareSuccessEvent event)
{
showMessage("Content shared successfully!");
}
@Override
public void onEvent(ShareErrorEvent event)
{
showMessage("Share failed: " + event.getMessage());
}
}
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidChecks if the Web Share API is supported by the browser with current page context.static voidcheckSupport(HtmlPage page) Checks if the Web Share API is supported by the browser.static voidShares content using the native share dialog.static voidshare(ShareListener listener, String text, String title, String url) Shares content using the native share dialog with current page context.static voidshareText(HtmlPage page, ShareListener listener, String text) Shares text content using the native share dialog.static voidshareText(ShareListener listener, String text) Shares text content using the native share dialog with current page context.static voidshareUrl(HtmlPage page, ShareListener listener, String url) Shares a URL using the native share dialog.static voidshareUrl(HtmlPage page, ShareListener listener, String title, String url) Shares a URL with title using the native share dialog.static voidshareUrl(ShareListener listener, String url) Shares a URL using the native share dialog with current page context.static voidshareUrl(ShareListener listener, String title, String url) Shares a URL with title using the native share dialog with current page context.
-
Constructor Details
-
ShareApi
public ShareApi()
-
-
Method Details
-
checkSupport
public static void checkSupport()Checks if the Web Share API is supported by the browser with current page context.Note: This executes JavaScript that logs to console. For programmatic checks, use feature detection on the client side.
-
checkSupport
Checks if the Web Share API is supported by the browser.Note: This executes JavaScript that logs to console. For programmatic checks, use feature detection on the client side.
- Parameters:
page- The page context.