Shift2App
Home chevron_right Device Information
smartphone

Device Information

Battery, network, device details, and location

Device Details

Get device manufacturer, model, and OS

shift2appjs.getDeviceInfo()

Returns detailed information about the device.

Returns

String - JSON object with device details

javascript
// Get device info
const device = JSON.parse(shift2appjs.getDeviceInfo());

console.log("Manufacturer:", device.manufacturer); // "Samsung"
console.log("Model:", device.model);               // "Galaxy S21"
console.log("Android Version:", device.version);  // "12"
console.log("SDK:", device.sdk);                  // 31

// Use for analytics
analytics.setUserProperties({
    device_model: device.model,
    os_version: device.version
});

Battery

Monitor battery level and charging state

shift2appjs.getBatteryLevel()

Returns the current battery level as a percentage.

Returns

Number - Battery percentage (0-100)

javascript
// Get battery level
const battery = shift2appjs.getBatteryLevel();
console.log("Battery:", battery + "%");

// Show warning if low
if (battery < 20) {
    showLowBatteryWarning();
}
shift2appjs.isCharging()

Checks if the device is currently charging.

Returns

Boolean - true if charging

javascript
// Check charging status
if (shift2appjs.isCharging()) {
    console.log("Device is charging");
} else if (shift2appjs.getBatteryLevel() < 15) {
    shift2appjs.showToast("Low battery! Please charge your device.");
}

Network

Check connectivity status

shift2appjs.getNetworkStatus()

Returns the current network connection type.

Returns

String - "wifi", "mobile", or "none"

javascript
// Check network
const network = shift2appjs.getNetworkStatus();

if (network === "none") {
    showOfflineMessage();
} else if (network === "mobile") {
    // Warn before large downloads
    if (!confirm("You are on mobile data. Download anyway?")) {
        return;
    }
}
shift2appjs.isOnline()

Checks if device has internet connection.

Returns

Boolean - true if connected

javascript
// Simple online check
if (!shift2appjs.isOnline()) {
    alert("No internet connection");
    return;
}

// Fetch with offline handling
async function fetchData(url) {
    if (!shift2appjs.isOnline()) {
        return getCachedData(url);
    }
    const response = await fetch(url);
    cacheData(url, response);
    return response;
}

Location

Get device GPS location

warning
Permission Required

Location must be enabled in app configuration and user must grant permission.

shift2appjs.getLocation(callbackName)

Gets current GPS coordinates. Requires location permission.

Parameters
callbackName String - Function to receive location data
Returns

void

javascript
// Get location
function onLocationReceived(success, lat, lng, accuracy) {
    if (success) {
        console.log("Location:", lat, lng);
        console.log("Accuracy:", accuracy, "meters");
        showOnMap(lat, lng);
    } else {
        alert("Could not get location. Please enable GPS.");
    }
}

shift2appjs.getLocation("onLocationReceived");
dashboard Dashboard menu_book Docs science Playground