react-native-bug-reporter 1.0.0 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,9 +3,14 @@
3
3
  <!-- Official screenshot detection on Android 14+ (no runtime prompt). -->
4
4
  <uses-permission android:name="android.permission.DETECT_SCREEN_CAPTURE" />
5
5
 
6
- <!-- MediaStore fallback for screenshot detection on Android 13 and below. -->
6
+ <!-- MediaStore fallback for screenshot detection on Android 13. -->
7
7
  <uses-permission
8
8
  android:name="android.permission.READ_MEDIA_IMAGES"
9
9
  android:maxSdkVersion="33" />
10
10
 
11
+ <!-- MediaStore fallback for Android 12L and below (older devices). -->
12
+ <uses-permission
13
+ android:name="android.permission.READ_EXTERNAL_STORAGE"
14
+ android:maxSdkVersion="32" />
15
+
11
16
  </manifest>
@@ -1,6 +1,8 @@
1
1
  package com.bugreporter
2
2
 
3
+ import android.Manifest
3
4
  import android.app.Activity
5
+ import android.content.pm.PackageManager
4
6
  import android.database.ContentObserver
5
7
  import android.graphics.Bitmap
6
8
  import android.net.Uri
@@ -50,10 +52,32 @@ class ScreenshotDetectorModule(private val reactContext: ReactApplicationContext
50
52
  if (Build.VERSION.SDK_INT >= 34) {
51
53
  registerScreenCaptureCallback()
52
54
  } else {
55
+ // Older devices detect screenshots via MediaStore, which needs the media
56
+ // read permission granted at runtime.
57
+ requestStoragePermissionIfNeeded()
53
58
  registerContentObserver()
54
59
  }
55
60
  }
56
61
 
62
+ /**
63
+ * Requests the media-read permission on Android 13- so the MediaStore
64
+ * ContentObserver reliably receives screenshot notifications. No-op on
65
+ * Android 14+ (the official ScreenCaptureCallback needs no permission).
66
+ */
67
+ private fun requestStoragePermissionIfNeeded() {
68
+ val activity = reactContext.currentActivity ?: return
69
+ val perm =
70
+ if (Build.VERSION.SDK_INT >= 33) Manifest.permission.READ_MEDIA_IMAGES
71
+ else Manifest.permission.READ_EXTERNAL_STORAGE
72
+ try {
73
+ if (activity.checkSelfPermission(perm) != PackageManager.PERMISSION_GRANTED) {
74
+ activity.requestPermissions(arrayOf(perm), PERMISSION_REQUEST_CODE)
75
+ }
76
+ } catch (_: Exception) {
77
+ // Ignore — observer is still registered; some OEMs notify without it.
78
+ }
79
+ }
80
+
57
81
  @ReactMethod
58
82
  fun stop() {
59
83
  isListening = false
@@ -223,5 +247,6 @@ class ScreenshotDetectorModule(private val reactContext: ReactApplicationContext
223
247
 
224
248
  companion object {
225
249
  const val NAME = "RNBugReporterScreenshot"
250
+ private const val PERMISSION_REQUEST_CODE = 7322
226
251
  }
227
252
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-bug-reporter",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
4
4
  "description": "Universal React Native bug reporter: auto-detect screenshots, annotate, collect device/app/user context, and ship to Supabase (Postgres + Storage) with Edge Function email.",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",