Repository navigation
Expand file tree
/
Copy pathcustomManifest.plugin.js
More file actions
37 lines (30 loc) · 1.61 KB
/
Copy pathcustomManifest.plugin.js
File metadata and controls
37 lines (30 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const { withAndroidManifest, AndroidConfig } = require('expo/config-plugins');
const SERVICE_NAME = 'app.notifee.core.ForegroundService';
const withForegroundService = (config) => {
return withAndroidManifest(config, async (config) => {
const manifest = config.modResults;
if (!manifest.manifest.$['xmlns:tools']) {
manifest.manifest.$['xmlns:tools'] = 'http://schemas.android.com/tools';
}
const mainApplication = AndroidConfig.Manifest.getMainApplicationOrThrow(manifest);
mainApplication['service'] = mainApplication['service'] || [];
// Idempotent: a prebuild that reuses an existing android/ dir already has this service in
// the base manifest — and non-clean prebuilds have already accumulated duplicates there — so
// drop every copy before adding the canonical one.
const serviceEntry = {
$: {
'android:name': SERVICE_NAME,
// microphone only. mediaPlayback and connectedDevice are intentionally absent: this
// service backs PTT capture, expo-audio owns its own mediaPlayback service for stream
// playback, and Bluetooth PTT handsets run on the same microphone session. Play rejects
// foreground-service types whose use case cannot be demonstrated in the app.
'android:foregroundServiceType': 'microphone',
'tools:replace': 'android:foregroundServiceType',
},
};
mainApplication['service'] = mainApplication['service'].filter((service) => service?.$?.['android:name'] !== SERVICE_NAME);
mainApplication['service'].push(serviceEntry);
return config;
});
};
module.exports = withForegroundService;