workPro Documentation
Downloads & Setup
DOWNLOAD_PERMISSIONS_GUIDE.md

WorkPro Download Permissions Guide

Overview

The WorkPro app now fully supports file downloads from WebView with automatic permission handling during installation and runtime.

Permissions Declared (AndroidManifest.xml)

<!-- For Android 9 and below - Write access to public storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="29" />

<!-- For Android 10-12 - Read media files from storage -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />

<!-- For Android 13+ - Read specific media types without broad storage permission -->
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />

<!-- Download notifications without user interaction -->
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />

How Downloads Work

1. User Clicks Download Button

  • When user clicks a download link in the WebView (PHP/HTML button)
  • The DownloadListener.onDownloadStart() is triggered
  • The app checks download permissions based on Android version

2. Permission Check

  • Android 10+: Files download to app-specific directory (/Android/data/com.workpro.app/files/Download/) - NO permission needed
  • Android 9 and below: Files download to public directory (/Downloads/) - Requires WRITE_EXTERNAL_STORAGE permission

3. Permission Request (if needed)

  • If running on Android 9 or below without permissions:
    • System shows permission dialog to user
    • User grants or denies permission
    • If granted, download proceeds
    • If denied, error message is shown

4. Download Execution

  • Uses Android DownloadManager service
  • Shows system notification with download progress
  • File saved with original filename
  • Notification shows "Download completed" when done

5. File Access

  • Android 10+: User can access via Settings > Apps > WorkPro > Files > Download
  • Android 9 and below: User can access via File Manager > Downloads

Download Locations by Android Version

Android Version Location Permission
13+ /Android/data/com.workpro.app/files/Download/ Not needed (app-specific)
10-12 /Android/data/com.workpro.app/files/Download/ Not needed (app-specific)
9 and below /storage/emulated/0/Download/ WRITE_EXTERNAL_STORAGE

Installation Permissions

When user installs the APK, Android shows these permissions:

Installation Dialog:

  • "Storage" - Allows saving downloads (Android 9 and below)
  • "Photos, media, and files" - Allows read access (Android 10-12)
  • "Photos and videos" - Allows media access (Android 13+)

User can grant or skip these permissions at installation time.

Runtime Permission Handling

If user skipped permissions at install time:

  1. When they click download button on first use
  2. System shows permission dialog
  3. User can grant permission
  4. Download proceeds immediately

Code Implementation Details

Main Download Handler (MainActivity.java):

// Triggered when user clicks download link
webView.setDownloadListener(new DownloadListener() {
    @Override
    public void onDownloadStart(String url, String userAgent, 
                                String contentDisposition, String mimetype, 
                                long contentLength) {
        handleDownload(url, userAgent, contentDisposition, mimetype, contentLength);
    }
});

Download Flow:

  1. handleDownload() - Checks permissions
  2. requestDownloadPermissions() - Requests if needed
  3. startDownload() - Executes download using DownloadManager

Permission Check:

private boolean hasDownloadPermissions() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        // Android 10+ - no permission needed
        return true;
    } else {
        // Android 9 and below - check WRITE_EXTERNAL_STORAGE
        return ContextCompat.checkSelfPermission(this, 
            Manifest.permission.WRITE_EXTERNAL_STORAGE) 
            == PackageManager.PERMISSION_GRANTED;
    }
}

Testing Downloads

To Test:

  1. Create a download link in your PHP/HTML:

    <a href="https://yourserver.com/files/document.pdf" download>Download PDF</a>
  2. Click the link in the app

  3. Grant permission when prompted

  4. File downloads to app Downloads folder

  5. Notification shows completion

Troubleshooting:

  • "Permission denied" → Grant storage permission in app settings
  • Download not starting → Check internet connection
  • Can't find file → Check app Downloads folder or system Downloads folder
  • URL error → Check file URL is accessible and public

Important Notes

  1. App-Specific Storage (Android 10+)

    • More secure and private
    • User can access via app settings
    • No scoped storage issues
  2. Public Storage (Android 9 and below)

    • Files visible in system Downloads
    • Requires explicit permission
    • May have security implications
  3. Permission Best Practice

    • Request only necessary permissions
    • At install time AND runtime
    • Current implementation is optimal

User Experience Flow

User clicks download link
    ↓
App checks Android version
    ↓
Android 10+? → Download starts immediately
    ↓
Android 9 or below?
    ↓
Has WRITE_EXTERNAL_STORAGE permission?
    ├─ YES → Download starts
    └─ NO → Show permission dialog
              ↓
          User grants? → Download starts
              ↓
          User denies? → Show error message

Files Modified

  • app/src/main/AndroidManifest.xml - Permissions declared
  • app/src/main/java/com/workpro/app/MainActivity.java - Download handling code
  • app/src/main/java/com/workpro/app/WorkProApplication.java - Global app configuration

Version Compatibility

  • ✅ Android 9 (API 28)
  • ✅ Android 10 (API 29)
  • ✅ Android 11 (API 30)
  • ✅ Android 12 (API 31-32)
  • ✅ Android 13 (API 33)
  • ✅ Android 14 (API 34) - Target SDK
workPro Documentation | v1.3
Login to Dashboard