react-native-screencapturee
v0.0.10
Published
Simple React Native Android module to request screen-capture permission and capture a screenshot with Media Projection Api, By Adnan
Maintainers
Readme
react-native-screencapture
Simple React Native Android module to request screen-capture permission and capture a screenshot (returns { path, base64 }).
Install
# or from npm if published
npm install react-native-screencapture
# rebuild app
cd android && ./gradlew clean && cd ..
npx react-native run-androidRequired AndroidManifest entries
Add these to android/app/src/main/AndroidManifest.xml (inside <manifest>):
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />Also declare a foreground service (inside <application>):
<service
android:name=".YourProjectionService"
android:exported="false"
android:foregroundServiceType="mediaProjection" />Notes: app saves screenshots to app external files or cache. On Android 10+ scoped storage applies; saving to your app folder does not require extra runtime permission.
Minimal usage
import RNScreenCapture from 'react-native-screencapturee';
// request permission (shows system dialog)
await RNScreenCapture.requestPermission();
// capture screenshot (after permission)
const { path, base64 } = await RNScreenCapture.captureScreenshot();
console.log('Saved at', path);API
requestPermission(): Promise<boolean>— show system permission dialog, resolvestruewhen granted.captureScreenshot(): Promise<{ path: string, base64: string }>— capture and return saved file path + base64 PNG.
Quick notes
- Android only (API 21+). iOS not supported for full-device capture.
- To capture while app is backgrounded, implement a foreground service (
YourProjectionService) that holds the MediaProjection token and runsVirtualDisplaythere. SYSTEM_ALERT_WINDOW(overlay) must be granted by the user in system settings — openSettings.ACTION_MANAGE_OVERLAY_PERMISSIONfrom native code.- Some apps block screenshots with
FLAG_SECURE— cannot be bypassed. - Always inform users and show a persistent notification when doing background capture.
Publish (short)
- Update
package.jsonversion and fields. npm packto test locally.npm publish --access public.
