CraftToNative Web SDK v1.0.0

Developer Documentation

Bridge your web application directly with native Android capabilities. Access Firebase Cloud Messaging, Play Billing, Native Sharing, and custom WebView JS bridge events with simple JavaScript callbacks.

Interactive JS Bridge Tester

Test SDK Methods Live

Run native invocations inside your app or view web fallbacks using our interactive live Developer Console.

Open Live Console

Installation

Android NativeUniversal JSiOS (Roadmap)

Include the official CraftToNative client SDK script in your HTML file. Place it in your document's <head> or right before the closing </body> tag.

<script src="https://craftonative.praptechie.in/sdk/craft-to-native-sdk.min.js"></script>

Initialization & Usage

Android NativeBuilt-in FallbacksiOS (Roadmap)

Once loaded, the SDK attaches a global window.CTN object. You can inspect runtime native detection via CTN.isNativeApp().

if (typeof window !== 'undefined' && window.CTN && window.CTN.isNativeApp()) {
  console.log("🚀 Active inside CraftToNative App!");
} else {
  console.log("🌐 Running in standard browser environment.");
}
Automatic Fallbacks: If called in standard desktop or mobile web browsers, CTN methods output standard web alerts or web share popups without throwing exceptions.

App & Device Information

Android NativeWeb MetadataiOS (Roadmap)

Fetch native app package metadata and physical hardware specs (device model, Android OS version, SDK build).

// 1. Fetch App Package Metadata
CTN.App.getInfo(function(info) {
  console.log("App Name:", info.appName);
  console.log("Package:", info.packageName);
  console.log("Version:", info.versionName);
  console.log("Platform:", info.platform);
});

// 2. Fetch Device Hardware Specifications
CTN.Device.getInfo(function(info) {
  console.log("Model:", info.model);
  console.log("Manufacturer:", info.manufacturer);
  console.log("Android OS Version:", info.osVersion);
});
Parameters Reference
NameTypeDescription
callback*reqFunctionCallback receiving app metadata object (appName, packageName, versionName, platform)

Push Notifications (FCM)

Test Live in Console
Android NativeFallback NulliOS (Roadmap)

Retrieve the Firebase Cloud Messaging registration token to dispatch targeted push notifications to the user device.

// Fetch FCM Device Token
CTN.Fcm.getToken(function(token) {
  if (token) {
    console.log("FCM Registration Token:", token);
    // Send token to your backend user database
  }
});

// Request Push Permission Prompt
CTN.Fcm.requestNotificationPermission(function(granted) {
  console.log("Permission Status:", granted);
});
Parameters Reference
NameTypeDescription
callback*reqFunctionCallback receiving string token or null if permission/FCM disabled

Native Page Loader Overlay

Test Live in Console
Android NativeConsole LoggingiOS (Roadmap)

Display a native Android spinner overlay during async API calls or heavy computations.

// Show Loader
CTN.Loader.show("api_request_123");

// Hide Loader
CTN.Loader.hide("api_request_123");

Activity & Clipboard Controls

Android NativePartialiOS (Roadmap)

Manage copy/paste permissions, clear WebView cache, or exit native activity.

// 1. Enable/Disable Clipboard Copy-Paste
CTN.Clipboard.setPolicy(true); // allow copy

// 2. Clear WebView Cache & Local Storage
CTN.App.clearCache();

// 3. Terminate Native App Activity
CTN.App.close();

Native Sharing

Test Live in Console
Android NativeWeb Share APIiOS (Roadmap)

Open the native Android share modal to share promotional copy, links, or text.

CTN.Share.text("Convert your website to native mobile app!", "CraftToNative App");
Parameters Reference
NameTypeDescription
text*reqstringText message or URL to share
titlestringShare dialog window header title

Toast Messages

Test Live in Console
Android NativeBrowser AlertiOS (Roadmap)

Display native Android toast popups directly from client-side JS.

CTN.Toast.show("Changes saved successfully!");

In-App Reviews

Test Live in Console
Android NativePlay Store LinkiOS (Roadmap)

Prompt the Google Play Store in-app rating flow directly inside your app.

CTN.Review.request();
Android NativeFallback NulliOS (Roadmap)

Check if a newer version of your app is published on the Google Play Store.

CTN.Update.check();

In-App Purchases & Subscriptions (IAP)

Test Live in Console
Android NativeSimulatoriOS (StoreKit Ready)

Trigger Google Play Billing & Apple StoreKit purchase sheets directly from JavaScript.

// 1. Purchase Product or Subscription
CTN.Iap.purchase({
  type: 'subscription', // 'one_time' | 'subscription'
  id: 'premium_monthly'
}, function(res) {
  if (res.status === 'success') {
    console.log('Purchase Token:', res.purchaseToken);
  }
});

// 2. Query Active Purchases
CTN.Iap.getPurchases(function(res) {
  console.log('Active Entitlements:', res.purchases);
});
Parameters Reference
NameTypeDescription
payload.type*req'one_time' | 'subscription'Purchase product category type
payload.id*reqstringProduct SKU ID configured in Google Play Console
callback*reqFunctionCompletion handler returning status and purchaseToken

Blob Downloads

Test Live in Console
Android NativeHTML AnchoriOS (Roadmap)

Hand over Base64 encoded blobs (PDFs, images, CSVs) directly to the native Android Download Manager.

const base64Data = "JVBERi0xLjQKJ...";
CTN.Download.sendBlob(base64Data, "application/pdf", "receipt.pdf");

App Lifecycle & Network Events

Android NativeWindow EventsiOS (Roadmap)

Subscribe to native Android lifecycle events and internet connection status transitions.

// 1. App Resume Listener
CTN.onAppResume(function() {
  console.log("App resumed from background");
});

// 2. Disconnected Network
CTN.onNoInternet(function() {
  console.log("Offline connection detected");
});

// 3. Internet Restored
CTN.onInternetRestored(function() {
  console.log("Network online restored");
});

Custom Bridge (postMessage)

Test Live in Console
Android NativeConsole LoggingiOS (Roadmap)

Dispatch custom key-value events to native WebView handlers.

CTN.Bridge.send("custom_analytics_event", {
  event: "checkout_clicked",
  amount: 29.00
});

Common Use Cases

Targeted Push Notifications

Call CTN.Fcm.getToken() after user login to register device tokens for transactional push alerts.

Play Store Rating Prompts

Trigger CTN.Review.request() after successful user checkout or completed milestone.

Adaptive Web Layouts

Hide web app install banners or tune header spacing when CTN.isNativeApp() evaluates to true.

Native Storage Downloads

Save PDF invoices or generated receipts directly into device downloads folder via CTN.Download.sendBlob().