Camera
Helps customers to enable camera access on the device.
Description
The requestCameraPermission() action triggers the native permission prompt on the user's device, allowing your app to request access to the device camera.
This action is primarily used when a feature requires capturing photos or scanning barcodes (e.g., uploading a profile picture or scanning a physical product). When invoked, the device will display the OS-native permission dialog (iOS/Android), and the user can choose to allow or deny access.
Function Signature
VajroSDK.actions.requestCameraPermission();Structure of Response
| Status | Response |
|---|---|
| Success | { "status": "success", "message": "Action executed" } |
| Failed | { "status": "failed", "message": "Action not executed " } |
| Unexpected Error | { "status": "error", "errorId": 500, "errorHandle": "unknown-error", "message": "Something unexpected happened" } |
Example Usage
document.getElementById('cameraBtn').addEventListener('click', async () => {
try {
VajroSDK.actions.requestCameraPermission();
} catch (err) {
console.error("Permission error:", error);
}
});
.permission-card {
padding: 24px;
border-radius: 12px;
background: #ffffff;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
text-align: center;
max-width: 320px;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.icon-container {
font-size: 40px;
margin-bottom: 16px;
}
.primary-btn {
background-color: #007AFF; /* Native iOS Blue */
color: white;
border: none;
padding: 12px 24px;
border-radius: 8px;
font-weight: 600;
cursor: pointer;
transition: background 0.3s ease;
}
.primary-btn:active {
background-color: #0056b3;
}
.status-text {
margin-top: 12px;
font-size: 14px;
}<div class="permission-card">
<div class="icon-container">
<i class="camera-icon">📷</i>
</div>
<h3>Enable Camera Access</h3>
<p>To personalize your experience and scan product barcodes, please enable camera permissions.</p>
<button id="cameraBtn" class="primary-btn">Allow Camera</button>
<p id="statusMsg" class="status-text"></p>
</div>Best Practices
- Context is Key: Only request camera access when the user interacts with a feature that clearly requires it (like clicking a "Scan" button).
- Pre-permission Dialog: Consider showing a custom UI explaining why the camera is needed before triggering the system prompt to increase opt-in rates.
- Handle Denials: If a user denies permission, provide clear instructions on how they can enable it via the device system settings.
Caveats
- The OS-native prompt may only appear once. If the user permanently denies the request, subsequent calls may not trigger the popup; you must guide the user to Settings.
Updated about 3 hours ago