HTML to APK Builder

ANDROIDAPI REFERENCE

AndroidAPI: httpGet and standard web APIs in generated apps

Reference for the native httpGet request and the browser features that work in generated apps: fetch, popups, web share, notifications, orientation lock and geolocation.

Updated:

Most web features work in a generated app as they do in Chrome. This page lists the native request method and what the app adds to standard browser APIs.

httpGet

AndroidAPI.httpGet(url, callbackId)

Makes a native HTTP(S) GET request and returns the response as text. Because the request is made by Android rather than the page, browser CORS rules do not apply. Use it to read a public JSON feed or API that does not send CORS headers.

  • Needs the INTERNET permission.
  • Up to 5 redirects are followed. Connection timeout is 15 s and read timeout 30 s.
  • Only GET. There are no custom headers, request bodies, cookies or streaming.

Result event: httpResult {callbackId, success, status, body, error}. success is true for HTTP status 200–299. On a network failure, status is missing and error contains the reason.

window.addEventListener('httpResult', e => {
  const r = e.detail;
  if (r.callbackId !== 'rates') return;
  if (!r.success) return showMessage(r.status ? 'Server error ' + r.status : 'Offline: ' + r.error);
  try { renderRates(JSON.parse(r.body)); }
  catch { showMessage('Unexpected response'); }
});
AndroidAPI.httpGet('https://example.com/api/rates.json', 'rates');

For POST requests, authentication headers or APIs that support CORS, use fetch(). Never put private API keys in your HTML: anyone can extract them from the APK.

fetch and XMLHttpRequest

Work as in a browser, with the usual CORS rules. Declare INTERNET. Prefer https:// addresses.

const res = await fetch('https://example.com/api/items');
if (!res.ok) throw new Error('HTTP ' + res.status);
const items = await res.json();
  • Normal links navigate inside the app. The Android back button goes back in page history before closing the app.
  • window.open() and target="_blank" open a popup window above the page with a close button, if the user tapped something to open it. The popup can talk to your page with window.opener.postMessage, which makes OAuth and payment pages work. Popups do not get AndroidAPI.
  • For URL projects, AndroidAPI is available only on your own site and its subdomains by default. Pages from other sites and embedded third-party frames cannot call it.
if (navigator.canShare && navigator.canShare({ files: [file] })) {
  await navigator.share({ title: 'Photo', files: [file] });
} else {
  await navigator.share({ title: 'My app', text: 'Try this', url: 'https://example.com' });
}

Works in generated apps and opens Android’s share sheet. Internally it uses shareText and shareFileFromBase64.

Notification

Notification.requestPermission() and new Notification(title, {body}) show native notifications. Declare POST_NOTIFICATIONS. See notifications for scheduled reminders.

screen.orientation.lock

await screen.orientation.lock('landscape'); // e.g. when a game starts
screen.orientation.unlock();                // back to the project's orientation

Lets one screen of your app switch orientation, such as a video player or a game. unlock() returns to the orientation you chose in the project settings.

Geolocation, camera and microphone

navigator.geolocation, getUserMedia({video}) and getUserMedia({audio}) work when the matching permissions (location, CAMERA, RECORD_AUDIO) are declared in the project. The app asks the user when the page requests access. Without the declaration they fail as if the user denied access. Details: location, camera.

Storage and offline

localStorage, sessionStorage, IndexedDB and cookies persist between launches. Local projects run offline as long as they do not load scripts or fonts from the internet. See offline apps.

What is not available

There is no AndroidAPI method for running a server, a login system, cloud sync, in-app payments or arbitrary Android code. Use a web service (for example Firebase or your own backend) through fetch for those.