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.
Test SDK Methods Live
Run native invocations inside your app or view web fallbacks using our interactive live Developer Console.
Installation
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
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.");
}App & Device Information
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);
});| Name | Type | Description |
|---|---|---|
| callback*req | Function | Callback receiving app metadata object (appName, packageName, versionName, platform) |
Push Notifications (FCM)
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);
});| Name | Type | Description |
|---|---|---|
| callback*req | Function | Callback receiving string token or null if permission/FCM disabled |
Native Page Loader Overlay
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
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();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");| Name | Type | Description |
|---|---|---|
| text*req | string | Text message or URL to share |
| title | string | Share dialog window header title |
Toast Messages
Display native Android toast popups directly from client-side JS.
CTN.Toast.show("Changes saved successfully!");In-App Reviews
Prompt the Google Play Store in-app rating flow directly inside your app.
CTN.Review.request();App Updates
Check if a newer version of your app is published on the Google Play Store.
CTN.Update.check();In-App Purchases & Subscriptions (IAP)
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);
});| Name | Type | Description |
|---|---|---|
| payload.type*req | 'one_time' | 'subscription' | Purchase product category type |
| payload.id*req | string | Product SKU ID configured in Google Play Console |
| callback*req | Function | Completion handler returning status and purchaseToken |
Blob Downloads
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
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)
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().
