Skip to content

Commit 7363fd5

Browse files
authored
Add use fullscreen intent (#944)
1 parent 685da2a commit 7363fd5

File tree

17 files changed

+84
-4
lines changed

17 files changed

+84
-4
lines changed

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,16 +811,17 @@ requestMultiple([PERMISSIONS.IOS.CAMERA, PERMISSIONS.IOS.FACE_ID]).then((statuse
811811

812812
#### openSettings
813813

814-
Open application / alarms / notifications settings (default to `application`).
814+
Open application / alarms / notifications / fullscreen settings (default to `application`).
815815

816816
> [!NOTE]
817817
>
818818
> - `notifications` settings are only available on Android 8+ and iOS 15.4+
819819
> - `alarms` settings are only available on Android 12+
820+
> - `fullscreen` settings are only available on Android 14+
820821
> - If a choice is not available, it fallbacks to `application` settings
821822
822823
```ts
823-
function openSettings(type?: 'application' | 'alarms' | 'notifications'): Promise<void>;
824+
function openSettings(type?: 'application' | 'alarms' | 'notifications' | 'fullscreen'): Promise<void>;
824825
```
825826

826827
```ts
@@ -845,6 +846,23 @@ canScheduleExactAlarms()
845846
.catch(() => console.warn('Cannot check exact alarms scheduling setting'));
846847
```
847848

849+
850+
#### canUseFullScreenIntent (Android)
851+
852+
Check if your app can use full screen intent.
853+
854+
```ts
855+
function canUseFullScreenIntent(): Promise<boolean>;
856+
```
857+
858+
```ts
859+
import {canUseFullScreenIntent} from 'react-native-permissions';
860+
861+
canUseFullScreenIntent()
862+
.then((value) => console.log(`Can use full screen intent: ${value}`))
863+
.catch(() => console.warn('Cannot check full screen intent using setting'));
864+
```
865+
848866
#### openPhotoPicker (iOS 14+)
849867

850868
Open a picker to update the photo selection when `PhotoLibrary` permission is `limited`. This will reject if unsupported or if full permission is already `granted`.

android/src/main/java/com/zoontek/rnpermissions/RNPermissionsModuleImpl.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.zoontek.rnpermissions
22

33
import android.app.AlarmManager
4+
import android.app.NotificationManager
45
import android.content.Context
56
import android.content.Intent
67
import android.content.pm.PackageManager
@@ -70,6 +71,10 @@ object RNPermissionsModuleImpl {
7071
setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
7172
putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
7273
}
74+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && type == "fullscreen" -> Intent().apply {
75+
setAction(Settings.ACTION_MANAGE_APP_USE_FULL_SCREEN_INTENT)
76+
setData(Uri.parse("package:${packageName}"))
77+
}
7378
else -> Intent().apply {
7479
setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
7580
setData(Uri.parse("package:${packageName}"))
@@ -96,6 +101,17 @@ object RNPermissionsModuleImpl {
96101
promise.resolve(canScheduleExactAlarms)
97102
}
98103

104+
fun canUseFullScreenIntent(reactContext: ReactApplicationContext, promise: Promise) {
105+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
106+
return promise.resolve(true)
107+
}
108+
109+
val notificationManager = reactContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
110+
val canUseFullScreenIntent = notificationManager.canUseFullScreenIntent()
111+
112+
promise.resolve(canUseFullScreenIntent)
113+
}
114+
99115
fun check(reactContext: ReactApplicationContext, permission: String, promise: Promise) {
100116
if (!isPermissionAvailable(permission)) {
101117
return promise.resolve(UNAVAILABLE)

android/src/newarch/com/zoontek/rnpermissions/RNPermissionsModule.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class RNPermissionsModule(reactContext: ReactApplicationContext?) :
2727
RNPermissionsModuleImpl.canScheduleExactAlarms(reactApplicationContext, promise)
2828
}
2929

30+
override fun canUseFullScreenIntent(promise: Promise) {
31+
RNPermissionsModuleImpl.canUseFullScreenIntent(reactApplicationContext, promise)
32+
}
33+
3034
override fun check(permission: String, promise: Promise) {
3135
RNPermissionsModuleImpl.check(reactApplicationContext, permission, promise)
3236
}

android/src/oldarch/com/zoontek/rnpermissions/RNPermissionsModule.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class RNPermissionsModule(reactContext: ReactApplicationContext?) :
3131
RNPermissionsModuleImpl.canScheduleExactAlarms(reactApplicationContext, promise)
3232
}
3333

34+
@ReactMethod
35+
fun canUseFullScreenIntent(promise: Promise) {
36+
RNPermissionsModuleImpl.canUseFullScreenIntent(reactApplicationContext, promise)
37+
}
38+
3439
@ReactMethod
3540
fun check(permission: String, promise: Promise) {
3641
RNPermissionsModuleImpl.check(reactApplicationContext, permission, promise)

ios/RNPermissions.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,11 @@ - (void)canScheduleExactAlarms:(RCTPromiseResolveBlock)resolve
460460
reject(@"RNPermissions:canScheduleExactAlarms", @"canScheduleExactAlarms is not supported on iOS", nil);
461461
}
462462

463+
- (void)canUseFullScreenIntent:(RCTPromiseResolveBlock)resolve
464+
reject:(RCTPromiseRejectBlock)reject {
465+
reject(@"RNPermissions:canUseFullScreenIntent", @"canUseFullScreenIntent is not supported on iOS", nil);
466+
}
467+
463468
- (void)shouldShowRequestRationale:(NSString *)permission
464469
resolve:(RCTPromiseResolveBlock)resolve
465470
reject:(RCTPromiseRejectBlock)reject {

mock.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const PERMISSIONS = {ANDROID, IOS, WINDOWS};
1313
export {PERMISSIONS, RESULTS};
1414

1515
export const canScheduleExactAlarms = jest.fn(async () => true);
16+
export const canUseFullScreenIntent = jest.fn(async () => true);
1617
export const check = jest.fn(async () => RESULTS.GRANTED);
1718
export const checkLocationAccuracy = jest.fn(async () => 'full');
1819
export const openPhotoPicker = jest.fn(async () => {});
@@ -70,6 +71,7 @@ export default {
7071
RESULTS,
7172

7273
canScheduleExactAlarms,
74+
canUseFullScreenIntent,
7375
check,
7476
checkLocationAccuracy,
7577
checkMultiple,

src/NativeRNPermissions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type NotificationsResponse = {
88

99
export interface Spec extends TurboModule {
1010
canScheduleExactAlarms(): Promise<boolean>;
11+
canUseFullScreenIntent(): Promise<boolean>;
1112
check(permission: string): Promise<string>;
1213
checkLocationAccuracy(): Promise<string>;
1314
checkMultiple(permissions: string[]): Promise<Object>;

src/contract.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ import type {
1010

1111
export type Contract = {
1212
canScheduleExactAlarms(): Promise<boolean>;
13+
canUseFullScreenIntent(): Promise<boolean>;
1314
check(permission: Permission): Promise<PermissionStatus>;
1415
checkLocationAccuracy(): Promise<LocationAccuracy>;
1516
checkMultiple<P extends Permission[]>(
1617
permissions: P,
1718
): Promise<Record<P[number], PermissionStatus>>;
1819
checkNotifications(): Promise<NotificationsResponse>;
1920
openPhotoPicker(): Promise<void>;
20-
openSettings(type?: 'application' | 'alarms' | 'notifications'): Promise<void>;
21+
openSettings(type?: 'application' | 'alarms' | 'notifications' | 'fullscreen'): Promise<void>;
2122
request(permission: Permission, rationale?: Rationale): Promise<PermissionStatus>;
2223
requestLocationAccuracy(options: LocationAccuracyOptions): Promise<LocationAccuracy>;
2324
requestMultiple<P extends Permission[]>(

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export {RESULTS} from './results';
88
export * from './types';
99

1010
export const canScheduleExactAlarms = methods.canScheduleExactAlarms;
11+
export const canUseFullScreenIntent = methods.canUseFullScreenIntent;
1112
export const check = methods.check;
1213
export const checkLocationAccuracy = methods.checkLocationAccuracy;
1314
export const checkMultiple = methods.checkMultiple;
@@ -24,6 +25,7 @@ export default {
2425
RESULTS,
2526

2627
canScheduleExactAlarms,
28+
canUseFullScreenIntent,
2729
check,
2830
checkLocationAccuracy,
2931
checkMultiple,

src/methods.android.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ const openSettings: Contract['openSettings'] = async (type = 'application') => {
4646
const canScheduleExactAlarms: Contract['canScheduleExactAlarms'] = () =>
4747
NativeModule.canScheduleExactAlarms();
4848

49+
const canUseFullScreenIntent: Contract['canUseFullScreenIntent'] = () =>
50+
NativeModule.canUseFullScreenIntent();
51+
4952
const check: Contract['check'] = async (permission) => {
5053
const status = (await NativeModule.check(permission)) as PermissionStatus;
5154
return status;
@@ -90,6 +93,7 @@ const requestMultiple: Contract['requestMultiple'] = (permissions) => {
9093

9194
export const methods: Contract = {
9295
canScheduleExactAlarms,
96+
canUseFullScreenIntent,
9397
check,
9498
checkLocationAccuracy,
9599
checkMultiple,

0 commit comments

Comments
 (0)