Skip to content

Latest commit

 

History

History
197 lines (129 loc) · 3.57 KB

File metadata and controls

197 lines (129 loc) · 3.57 KB

WebAppInterface Methods Documentation

This document describes all the interface methods available in questphone. check here for complete usage.

Check interface listener's code for questphone on android here

generate a quest to test every interface open setup

onQuestCompleted()

Marks the current quest as completed in the app.
Usage:

WebAppInterface.onQuestCompleted();

toast(msg: String)

Shows a toast message on the device. Usage:

WebApp.toast("Hello from JS!");

sendBroadcast(action: String, jsonData: String?)

Sends a broadcast with the specified action and optional JSON payload. Usage:

WebApp.sendBroadcast("ACTION_NAME", '{"key":"value"}');

getUserData(): String

Returns the current user data as a JSON string. Usage:

const userData = WebApp.getUserData();

registerReceiver(actionsJson: String)

Registers the WebView to listen for broadcasts. Provide a JSON array of actions. Usage:

WebApp.registerReceiver('["ACTION_1","ACTION_2"]');

unregisterAll()

Unregisters all broadcast receivers. Usage:

WebApp.unregisterAll();

isQuestCompleted(): Boolean

Returns true if the current quest is completed. Usage:

const completed = WebApp.isQuestCompleted();

enableFullScreen()

Enables fullscreen mode in the app. Usage:

WebApp.enableFullScreen();

disableFullScreen()

Disables fullscreen mode. Usage:

WebApp.disableFullScreen();

getVersion(): Int

Returns the app version code. Usage:

const version = WebApp.getVersion();

setAlarmedNotification(triggerMillis: Long, title: String, description: String)

Schedules a notification alarm at the given timestamp. Usage:

WebApp.setAlarmedNotification(Date.now() + 60000, "Reminder", "Time to do your quest!");

openApp(packageName: String)

Opens another app by package name or redirects to Play Store if not installed. Usage:

WebApp.openApp("com.example.app");

shareText(title: String, text: String)

Shares plain text using Android share sheet. Usage:

WebApp.shareText("Check this!", "Hello world");

shareImage(base64: String)

Shares an image provided as a Base64 string. Usage:

WebApp.shareImage("data:image/png;base64,iVBORw0KGgoAAAANS...");

getCoinRewardRatio(): Int

Returns the current coin reward ratio from app preferences. Usage:

const ratio = WebApp.getCoinRewardRatio();

getAllStatsForQuest()

Fetches all quest stats asynchronously and calls the JS function onStatsReceived(stats). Usage:

WebApp.getAllStatsForQuest();
function onStatsReceived(stats) {
    WebApp.toast("Stats: " + stats);
}

fetchDataWithoutCorsAsync(url: String, headersJson: String?, callback: String)

Fetches a URL without CORS restrictions. headersJson is optional. callback is the JS function to call with the response. Usage:

WebApp.fetchDataWithoutCorsAsync("https://example.com/data", '{"Authorization":"Bearer token"}', "handleFetch");
function handleFetch(result) {
    WebApp.toast(result);
}