Skip to content

Commit

Permalink
Merge pull request #1919 from leancodepl/fix/example_app_android_14
Browse files Browse the repository at this point in the history
Fix/example app android 14
  • Loading branch information
piotruela authored Nov 17, 2023
2 parents b8aad0e + 89f84e8 commit 86949c7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/test-android-device.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ jobs:
matrix:
flutter-version: ['3.16.x']
flutter-channel: ['stable']
device_model: ['oriole']
os: ['Android API']
os_version: ['33']
include:
- device_model: 'oriole'
os_version: '33'
- device_model: 'shiba'
os_version: '34'

defaults:
run:
Expand Down
14 changes: 13 additions & 1 deletion packages/patrol/example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:ignore="QueryAllPackagesPermission"/>

<application
Expand Down Expand Up @@ -35,10 +36,21 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver android:exported="false"
android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
<receiver android:exported="false"
android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2"/>
</application>
</manifest>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ void main() {
await $.native.grantPermissionWhenInUse();
}

// Android 14+ requires additional permission to schedule notifications.
// Workaround for conditionally granting permission.
final android14PermissionSelector = Selector(
text: 'Allow setting alarms and reminders',
);
final android14PermissionScreen = await $.native.getNativeViews(
android14PermissionSelector,
);
if (android14PermissionScreen.isNotEmpty) {
await $.native.tap(android14PermissionSelector);
await $.native.pressBack();
}

await $('Show in a few seconds').tap();
await $.native.pressHome();
await $.native.openNotifications();
Expand Down
4 changes: 4 additions & 0 deletions packages/patrol/example/lib/notifications_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class _NotificationsScreenState extends State<NotificationsScreen> {
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.requestNotificationsPermission();
await _notificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.requestExactAlarmsPermission();
}(),
);
}
Expand Down

0 comments on commit 86949c7

Please sign in to comment.