# Quick Build & Deploy Guide

## Prerequisites
- Basic4Android (B4A) IDE installed
- Android device with USB debugging enabled
- USB cable to connect device to computer

## Build Steps

1. **Open B4A IDE**
   - Launch Basic4Android IDE

2. **Load Project**
   - File → Open
   - Navigate to: `c:\xampp\htdocs\sdms_dashboard\SmartboardAgent\sba\sba.b4a`
   - Click Open

3. **Connect Device**
   - Connect Android device via USB
   - Enable USB debugging on device
   - Accept USB debugging prompt on device

4. **Compile & Install**
   - Press **F5** or click **"Compile & Run"** button
   - Wait for compilation to complete
   - APK will automatically install on device

## First Run

1. **Launch App**
   - Tap app icon on device
   - You'll see a toast: "SDMS Agent started in background"
   - App will close immediately (this is normal)

2. **Verify Service Running**
   - Swipe down notification tray
   - Look for: "SDMS Agent Running - Monitoring for messages..."
   - If you see this, the service is running correctly

3. **Check Dashboard**
   - Open web dashboard: http://localhost/sdms_dashboard
   - Go to Devices page
   - Your device should appear as "online"

## Testing Message Reception

1. **Send Test Broadcast**
   - Go to dashboard → Broadcasts
   - Click "New Broadcast"
   - Enter title and message
   - Select your device
   - Click Send

2. **Verify on Device**
   - Within 30 seconds, you should see a notification
   - Notification will have your broadcast title and message

## Troubleshooting

### Service Not Showing in Notifications
- Open app again
- Check Settings → Apps → SDMS Agent → Permissions
- Ensure "Notifications" permission is granted

### Device Not Appearing in Dashboard
- Check device has internet connection
- Wait 30 seconds for first heartbeat
- Check Logcat: `adb logcat | grep MessageService`

### Not Receiving Broadcasts
- Verify device shows as "online" in dashboard
- Check notification permissions
- Try sending another broadcast

## Enable Auto-Start on Boot

### For Most Devices
1. Settings → Apps → SDMS Agent
2. Enable "Auto-start" or "Start on boot"

### For Xiaomi/MIUI
1. Settings → Apps → Manage apps → SDMS Agent
2. Enable "Autostart"
3. Battery saver → Choose apps → SDMS Agent → No restrictions

### For Samsung
1. Settings → Apps → SDMS Agent → Battery
2. Select "Unrestricted"

### For Huawei/EMUI
1. Settings → Apps → SDMS Agent → Battery
2. Enable "App launch" → Manage manually
3. Enable all three options

## Viewing Logs

### Using ADB
```bash
# View all logs
adb logcat

# Filter MessageService logs
adb logcat | grep MessageService

# Filter all SDMS logs
adb logcat | grep -E "MessageService|Starter|Main"

# Save logs to file
adb logcat > sdms_logs.txt
```

## Uninstall

To completely remove the app:
```bash
adb uninstall com.smartboard.sdms.agent
```

Or from device:
1. Settings → Apps → SDMS Agent
2. Tap "Uninstall"
