Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,40 @@ void main() {
}
});

testWidgets('Launch throws when no Activity is found',
(WidgetTester tester) async {
testWidgets('Launch throws when no Activity is found', (
WidgetTester tester,
) async {
// We can't test that any of this is really working, this is mostly just
// checking that the plugin API is registered. Only works on Android.
const intent = AndroidIntent(action: 'LAUNCH', package: 'foobar');
await expectLater(() async => await intent.launch(), throwsA((Exception e) {
return e is PlatformException &&
e.message!.contains('No Activity found to handle Intent');
}));
await expectLater(
() async => await intent.launch(),
throwsA((Exception e) {
return e is PlatformException &&
e.message!.contains('No Activity found to handle Intent');
}),
);
}, skip: !Platform.isAndroid);

testWidgets('Set an alarm on weekdays at 9:30pm should not throw',
(WidgetTester tester) async {
testWidgets('Set an alarm on weekdays at 9:30pm should not throw', (
WidgetTester tester,
) async {
const intent = AndroidIntent(
action: 'android.intent.action.SET_ALARM',
arguments: <String, dynamic>{
'android.intent.extra.alarm.DAYS': <int>[2, 3, 4, 5, 6],
'android.intent.extra.alarm.HOUR': 21,
'android.intent.extra.alarm.MINUTES': 30,
'android.intent.extra.alarm.SKIP_UI': true,
'android.intent.extra.alarm.MESSAGE': 'Just for Integration test',
});
action: 'android.intent.action.SET_ALARM',
arguments: <String, dynamic>{
'android.intent.extra.alarm.DAYS': <int>[2, 3, 4, 5, 6],
'android.intent.extra.alarm.HOUR': 21,
'android.intent.extra.alarm.MINUTES': 30,
'android.intent.extra.alarm.SKIP_UI': true,
'android.intent.extra.alarm.MESSAGE': 'Just for Integration test',
},
);
await intent.launch();
}, skip: !Platform.isAndroid);

testWidgets('Parse and Launch should not throw', (WidgetTester tester) async {
const intent = 'intent:#Intent;'
const intent =
'intent:#Intent;'
'action=android.intent.action.SET_ALARM;'
'B.android.intent.extra.alarm.SKIP_UI=true;'
'S.android.intent.extra.alarm.MESSAGE=Create%20a%20Flutter%20app;'
Expand All @@ -86,47 +93,50 @@ void main() {
}, skip: !Platform.isAndroid);

testWidgets('sendService should not throw', (WidgetTester tester) async {
const intent = AndroidIntent(
action: 'com.example.service',
);
const intent = AndroidIntent(action: 'com.example.service');
await intent.sendService();
}, skip: !Platform.isAndroid);

testWidgets('SendBroadcast should not throw', (WidgetTester tester) async {
const intent = AndroidIntent(
action: 'com.example.broadcast',
);
const intent = AndroidIntent(action: 'com.example.broadcast');
await intent.sendBroadcast();
}, skip: !Platform.isAndroid);

testWidgets('CanResolveActivity returns true when example Activity is found',
(WidgetTester tester) async {
const intent = AndroidIntent(
action: 'action_view',
package: 'io.flutter.plugins.androidintentexample',
componentName: 'io.flutter.plugins.androidintentexample.MainActivity',
);
await expectLater(await intent.canResolveActivity(), isTrue);
}, skip: !Platform.isAndroid);
testWidgets(
'CanResolveActivity returns true when example Activity is found',
(WidgetTester tester) async {
const intent = AndroidIntent(
action: 'action_view',
package: 'io.flutter.plugins.androidintentexample',
componentName: 'io.flutter.plugins.androidintentexample.MainActivity',
);
await expectLater(await intent.canResolveActivity(), isTrue);
},
skip: !Platform.isAndroid,
);

testWidgets('CanResolveActivity returns false when no Activity is found',
(WidgetTester tester) async {
testWidgets('CanResolveActivity returns false when no Activity is found', (
WidgetTester tester,
) async {
const intent = AndroidIntent(action: 'LAUNCH', package: 'foobar');
await expectLater(await intent.canResolveActivity(), isFalse);
}, skip: !Platform.isAndroid);

testWidgets(
'getResolvedActivity return activity details when example Activity is found',
(WidgetTester tester) async {
final intent = AndroidIntent(
action: 'action_view',
data: Uri.encodeFull('http://'),
);
await expectLater(await intent.getResolvedActivity(), isNotNull);
}, skip: !Platform.isAndroid);
'getResolvedActivity return activity details when example Activity is found',
(WidgetTester tester) async {
final intent = AndroidIntent(
action: 'action_view',
data: Uri.encodeFull('http://'),
);
await expectLater(await intent.getResolvedActivity(), isNotNull);
},
skip: !Platform.isAndroid,
);

testWidgets('getResolvedActivity returns null when no Activity is found',
(WidgetTester tester) async {
testWidgets('getResolvedActivity returns null when no Activity is found', (
WidgetTester tester,
) async {
final intent = AndroidIntent(
action: 'action_view',
data: Uri.encodeFull('mycustomscheme://'),
Expand Down
78 changes: 39 additions & 39 deletions packages/android_intent_plus/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MyApp extends StatelessWidget {
home: const MyHomePage(),
routes: <String, WidgetBuilder>{
ExplicitIntentsWidget.routeName: (BuildContext context) =>
const ExplicitIntentsWidget()
const ExplicitIntentsWidget(),
},
);
}
Expand Down Expand Up @@ -58,7 +58,7 @@ class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
Widget body;
if (const LocalPlatform().isAndroid) {
if (NativePlatform.current?.isAndroid ?? false) {
body = Padding(
padding: const EdgeInsets.symmetric(vertical: 15.0),
child: Column(
Expand All @@ -67,7 +67,8 @@ class MyHomePage extends StatelessWidget {
ElevatedButton(
onPressed: _createAlarm,
child: const Text(
'Tap here to set an alarm\non weekdays at 9:30pm.'),
'Tap here to set an alarm\non weekdays at 9:30pm.',
),
),
ElevatedButton(
onPressed: _parseAndLaunch,
Expand Down Expand Up @@ -110,14 +111,13 @@ class MyHomePage extends StatelessWidget {
}

void _sendBroadcast() {
const intent = AndroidIntent(
action: 'com.example.broadcast',
);
const intent = AndroidIntent(action: 'com.example.broadcast');
intent.sendBroadcast();
}

void _parseAndLaunch() {
const intent = 'intent:#Intent;'
const intent =
'intent:#Intent;'
'action=android.intent.action.SET_ALARM;'
'B.android.intent.extra.alarm.SKIP_UI=true;'
'S.android.intent.extra.alarm.MESSAGE=Create%20a%20Flutter%20app;'
Expand All @@ -139,34 +139,39 @@ class ExplicitIntentsWidget extends StatelessWidget {

void _openGoogleMapsStreetView() {
final intent = AndroidIntent(
action: 'action_view',
data: Uri.encodeFull('google.streetview:cbll=46.414382,10.013988'),
package: 'com.google.android.apps.maps');
action: 'action_view',
data: Uri.encodeFull('google.streetview:cbll=46.414382,10.013988'),
package: 'com.google.android.apps.maps',
);
intent.launch();
}

void _displayMapInGoogleMaps({int zoomLevel = 12}) {
final intent = AndroidIntent(
action: 'action_view',
data: Uri.encodeFull('geo:37.7749,-122.4194?z=$zoomLevel'),
package: 'com.google.android.apps.maps');
action: 'action_view',
data: Uri.encodeFull('geo:37.7749,-122.4194?z=$zoomLevel'),
package: 'com.google.android.apps.maps',
);
intent.launch();
}

void _launchTurnByTurnNavigationInGoogleMaps() {
final intent = AndroidIntent(
action: 'action_view',
data: Uri.encodeFull(
'google.navigation:q=Taronga+Zoo,+Sydney+Australia&avoid=tf'),
package: 'com.google.android.apps.maps');
action: 'action_view',
data: Uri.encodeFull(
'google.navigation:q=Taronga+Zoo,+Sydney+Australia&avoid=tf',
),
package: 'com.google.android.apps.maps',
);
intent.launch();
}

void _openLinkInGoogleChrome() {
final intent = AndroidIntent(
action: 'action_view',
data: Uri.encodeFull('https://flutter.dev'),
package: 'com.android.chrome');
action: 'action_view',
data: Uri.encodeFull('https://flutter.dev'),
package: 'com.android.chrome',
);
intent.launch();
}

Expand All @@ -181,9 +186,10 @@ class ExplicitIntentsWidget extends StatelessWidget {

void _testExplicitIntentFallback() {
final intent = AndroidIntent(
action: 'action_view',
data: Uri.encodeFull('https://flutter.dev'),
package: 'com.android.chrome.implicit.fallback');
action: 'action_view',
data: Uri.encodeFull('https://flutter.dev'),
package: 'com.android.chrome.implicit.fallback',
);
intent.launch();
}

Expand Down Expand Up @@ -234,10 +240,7 @@ class ExplicitIntentsWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Test explicit intents'),
elevation: 4,
),
appBar: AppBar(title: const Text('Test explicit intents'), elevation: 4),
body: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(vertical: 15.0),
Expand All @@ -247,7 +250,8 @@ class ExplicitIntentsWidget extends StatelessWidget {
ElevatedButton(
onPressed: _openGoogleMapsStreetView,
child: const Text(
'Tap here to display panorama\nimagery in Google Street View.'),
'Tap here to display panorama\nimagery in Google Street View.',
),
),
const SizedBox(height: 16),
ElevatedButton(
Expand All @@ -258,7 +262,8 @@ class ExplicitIntentsWidget extends StatelessWidget {
ElevatedButton(
onPressed: _launchTurnByTurnNavigationInGoogleMaps,
child: const Text(
'Tap here to launch turn-by-turn\nnavigation in Google Maps.'),
'Tap here to launch turn-by-turn\nnavigation in Google Maps.',
),
),
const SizedBox(height: 16),
ElevatedButton(
Expand All @@ -274,7 +279,8 @@ class ExplicitIntentsWidget extends StatelessWidget {
ElevatedButton(
onPressed: _testExplicitIntentFallback,
child: const Text(
'Tap here to test explicit intent fallback to implicit.'),
'Tap here to test explicit intent fallback to implicit.',
),
),
const SizedBox(height: 16),
ElevatedButton(
Expand All @@ -286,23 +292,17 @@ class ExplicitIntentsWidget extends StatelessWidget {
const SizedBox(height: 16),
ElevatedButton(
onPressed: _openApplicationDetails,
child: const Text(
'Tap here to open Application Details',
),
child: const Text('Tap here to open Application Details'),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => _getResolvedActivity(context),
child: const Text(
'Tap here to get default resolved activity',
),
child: const Text('Tap here to get default resolved activity'),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: _openGmail,
child: const Text(
'Tap here to open gmail app with details',
),
child: const Text('Tap here to open gmail app with details'),
),
],
),
Expand Down
4 changes: 2 additions & 2 deletions packages/android_intent_plus/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ name: android_intent_plus_example
description: Demonstrates how to use the android_intent plugin.

environment:
sdk: ">=3.1.0 <4.0.0"
sdk: ">=3.10.0 <4.0.0"
flutter: ">=3.12.0"

dependencies:
flutter:
sdk: flutter
platform: ^3.1.0
platform: ^3.2.0
android_intent_plus: ^6.1.0

dev_dependencies:
Expand Down
Loading
Loading