Open Camera

Opens the device camera interface specifically configured for scanning.

Description

The OpenCamera({type:scan}) action launches the native camera view in "scanner mode." This is specifically optimized for recognizing barcodes or QR codes. Unlike a standard photo capture, this interface typically includes a viewfinder overlay and automatically processes the code once it enters the frame.

Function Signature

VajroSDK.actions.openCamera({ type: "scan" })

Structure of Response

StatusResponse
Success{ "status": "success", "message": "Action executed successfully" }
Cart not accessible{ "status": "error", "errorId": 400, "message": "Action not executed"}
Unexpected Error{ "status": "error", "errorId": 500, "errorHandle": "unknown-error", "message": "Something unexpected happened" }

Example Usage

async function handleScan() {
    try {
       VajroSDK.actions.openCamera({ type: "scan" });
    } catch (error) {
        console.error("Scan error", error);
    }
}
:root {
  --primary-blue: #007AFF;
  --success-green: #34C759;
  --card-bg: #ffffff;
  --text-main: #1C1C1E;
  --text-sub: #8E8E93;
  --bg-color: #F2F2F7;
}
.sdk-dashboard {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-color);
  padding: 20px;
  min-height: 100vh;
}
.dashboard-header {
  margin-bottom: 24px;
}
.dashboard-header h2 {
  margin: 0;
  font-size: 24px;
  color: var(--text-main);
}
.dashboard-header p {
  margin: 4px 0 0;
  color: var(--text-sub);
}
.action-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.action-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  transition: transform 0.2s ease;
}
.action-card:active {
  transform: scale(0.98);
  background: #FAFAFA;
}
.icon-wrapper {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}
.orders-bg { background: #E5F1FF; }
.camera-bg { background: #FFF4E5; }
.location-bg { background: #E5FFE9; }
.security-bg { background: #F2EBFF; }
.card-content h3 {
  margin: 0;
  font-size: 16px;
  color: var(--text-main);
}
.card-content p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-sub);
}
.permission-card {
  border: 1px dashed #D1D1D6;
}
<div class="sdk-dashboard">
   <header class="dashboard-header">
      <h2>App Services</h2>
      <p>Manage your account and device features</p>
   </header>
   <div class="action-grid">
      <div class="action-card" onclick="handleScan()">
         <div class="icon-wrapper camera-bg">🔍</div>
         <div class="card-content">
            <h3>Product Scanner</h3>
            <p>Scan a barcode to find products instantly.</p>
         </div>
      </div>
   </div>
</div>

Best Practices

  1. Verify Permissions Early: Check VajroSDK.variables.device.permissions.camera before launching the scanner. If the user hasn't granted access, the experience will break abruptly.
  2. Avoid "Scanner Loops": After a successful scan, navigate the user to the relevant product or result page immediately. Avoid returning them back to the camera unless they explicitly choose to "Scan Another Item."

Caveats

  1. Lighting & Clarity: Scanning performance is highly dependent on environmental factors; poor lighting or blurry camera lenses can cause the action to hang or fail to recognize codes.
  2. Format Support: The scanner is optimized for standard formats (QR, EAN, UPC). Custom or proprietary 2D codes may not be supported by the native underlying library.
  3. Permission Dependency: This action will fail immediately if the user has previously denied camera permissions. You should verify VajroSDK.variables.device.permissions.camera before calling this action to ensure a smooth UI flow.