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
6 changes: 5 additions & 1 deletion packages/android_intent_plus/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## 3.1.0

- Added `arrayArguments` to explicitly pass array values to an intent

## 3.0.2

- Fixed the buildIntent method to do not set the pacakage to null if it's not resolvable
- UPdated the example of resolving intent with explicitly defined package name
- Updated the example of resolving intent with explicitly defined package name

## 3.0.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
String category = call.argument("category");
Uri data = call.argument("data") != null ? Uri.parse((String) call.argument("data")) : null;
Bundle arguments = convertArguments((Map<String, ?>) call.argument("arguments"));
Bundle arrayArguments = convertArrayArguments((Map<String, ?>) call.argument("arrayArguments"));
arguments.putAll(arrayArguments);
String packageName = call.argument("package");
ComponentName componentName =
(!TextUtils.isEmpty(packageName)
Expand Down Expand Up @@ -166,6 +168,51 @@ private static Bundle convertArguments(Map<String, ?> arguments) {
return bundle;
}

private static Bundle convertArrayArguments(Map<String, ?> arrayArguments) {
Bundle bundle = new Bundle();
if (arrayArguments == null) {
return bundle;
}
for (String key : arrayArguments.keySet()) {
Object value = arrayArguments.get(key);
if (isTypedArrayList(value, Boolean.class)) {
ArrayList<Boolean> list = (ArrayList<Boolean>) value;
boolean[] array = new boolean[list.size()];
for (int i = 0; i < list.size(); i++) {
array[i] = list.get(i);
}
bundle.putBooleanArray(key, array);
} else if (isTypedArrayList(value, Integer.class)) {
ArrayList<Integer> list = (ArrayList<Integer>) value;
int[] array = new int[list.size()];
for (int i = 0; i < list.size(); i++) {
array[i] = list.get(i);
}
bundle.putIntArray(key, array);
} else if (isTypedArrayList(value, Long.class)) {
ArrayList<Long> list = (ArrayList<Long>) value;
long[] array = new long[list.size()];
for (int i = 0; i < list.size(); i++) {
array[i] = list.get(i);
}
bundle.putLongArray(key, array);
} else if (isTypedArrayList(value, Double.class)) {
ArrayList<Double> list = (ArrayList<Double>) value;
double[] array = new double[list.size()];
for (int i = 0; i < list.size(); i++) {
array[i] = list.get(i);
}
bundle.putDoubleArray(key, array);
} else if (isTypedArrayList(value, String.class)) {
ArrayList<String> list = (ArrayList<String>) value;
bundle.putStringArray(key, list.toArray(new String[list.size()]));
} else {
throw new UnsupportedOperationException("Unsupported type " + value);
}
}
return bundle;
}

private static boolean isTypedArrayList(Object value, Class<?> type) {
if (!(value instanceof ArrayList)) {
return false;
Expand Down
23 changes: 22 additions & 1 deletion packages/android_intent_plus/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,29 @@ class ExplicitIntentsWidget extends StatelessWidget {
intent.launch();
}

void _openGmail() {
const intent = AndroidIntent(
action: 'android.intent.action.SEND',
arguments: {'android.intent.extra.SUBJECT': 'I am the subject'},
arrayArguments: {
'android.intent.extra.EMAIL': ['[email protected]', '[email protected]'],
'android.intent.extra.CC': ['[email protected]', '[email protected]'],
'android.intent.extra.BCC': ['[email protected]', '[email protected]'],
},
package: 'com.google.android.gm',
type: 'message/rfc822',
);
intent.launch();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Test explicit intents'),
),
body: Center(
child: Padding(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(vertical: 15.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
Expand Down Expand Up @@ -235,6 +250,12 @@ class ExplicitIntentsWidget extends StatelessWidget {
'Tap here to open Application Details',
),
),
ElevatedButton(
onPressed: _openGmail,
child: const Text(
'Tap here to open gmail app with details',
),
),
],
),
),
Expand Down
13 changes: 13 additions & 0 deletions packages/android_intent_plus/lib/android_intent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class AndroidIntent {
/// intent.
/// [arguments] is the map that will be converted into an extras bundle and
/// passed to the intent.
/// [arrayArguments] is a map that will be converted into an extra bundle
/// as in an array and passed to the intent.
/// [package] refers to the package parameter of the intent, can be null.
/// [componentName] refers to the component name of the intent, can be null.
/// If not null, then [package] but also be provided.
Expand All @@ -34,6 +36,7 @@ class AndroidIntent {
this.category,
this.data,
this.arguments,
this.arrayArguments,
this.package,
this.componentName,
Platform? platform,
Expand All @@ -54,6 +57,7 @@ class AndroidIntent {
this.category,
this.data,
this.arguments,
this.arrayArguments,
this.package,
this.componentName,
this.type,
Expand Down Expand Up @@ -87,9 +91,17 @@ class AndroidIntent {
/// The equivalent of `extras`, a generic `Bundle` of data that the Intent can
/// carry. This is a slot for extraneous data that the listener may use.
///
/// If the argument contains a list value, then the value will be put in as an
/// array list.
///
/// See https://developer.android.com/reference/android/content/Intent.html#intent-structure.
final Map<String, dynamic>? arguments;

/// Similar to [arguments], but in this case the arguments are an array and
/// will be added to the intent as in an array extra instead of of an array
/// list.
final Map<String, List<dynamic>>? arrayArguments;

/// Sets the [data] to only resolve within this given package.
///
/// See https://developer.android.com/reference/android/content/Intent.html#setPackage(java.lang.String).
Expand Down Expand Up @@ -190,6 +202,7 @@ class AndroidIntent {
if (category != null) 'category': category,
if (data != null) 'data': data,
if (arguments != null) 'arguments': arguments,
if (arrayArguments != null) 'arrayArguments': arrayArguments,
if (package != null) ...{
'package': package,
if (componentName != null) 'componentName': componentName,
Expand Down
2 changes: 1 addition & 1 deletion packages/android_intent_plus/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: android_intent_plus
description: Flutter plugin for launching Android Intents. Not supported on iOS.
version: 3.0.2
version: 3.1.0
homepage: https://plus.fluttercommunity.dev/
repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/

Expand Down