diff --git a/packages/android_intent_plus/CHANGELOG.md b/packages/android_intent_plus/CHANGELOG.md index 04b29031c7..2c3844d712 100644 --- a/packages/android_intent_plus/CHANGELOG.md +++ b/packages/android_intent_plus/CHANGELOG.md @@ -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 diff --git a/packages/android_intent_plus/android/src/main/java/dev/fluttercommunity/plus/androidintent/MethodCallHandlerImpl.java b/packages/android_intent_plus/android/src/main/java/dev/fluttercommunity/plus/androidintent/MethodCallHandlerImpl.java index 7200e0528f..c6d4a9c381 100644 --- a/packages/android_intent_plus/android/src/main/java/dev/fluttercommunity/plus/androidintent/MethodCallHandlerImpl.java +++ b/packages/android_intent_plus/android/src/main/java/dev/fluttercommunity/plus/androidintent/MethodCallHandlerImpl.java @@ -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) call.argument("arguments")); + Bundle arrayArguments = convertArrayArguments((Map) call.argument("arrayArguments")); + arguments.putAll(arrayArguments); String packageName = call.argument("package"); ComponentName componentName = (!TextUtils.isEmpty(packageName) @@ -166,6 +168,51 @@ private static Bundle convertArguments(Map arguments) { return bundle; } + private static Bundle convertArrayArguments(Map 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 list = (ArrayList) 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 list = (ArrayList) 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 list = (ArrayList) 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 list = (ArrayList) 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 list = (ArrayList) 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; diff --git a/packages/android_intent_plus/example/lib/main.dart b/packages/android_intent_plus/example/lib/main.dart index ef8f4ba674..66e16da015 100644 --- a/packages/android_intent_plus/example/lib/main.dart +++ b/packages/android_intent_plus/example/lib/main.dart @@ -184,6 +184,21 @@ 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': ['eidac@me.com', 'overbom@mac.com'], + 'android.intent.extra.CC': ['john@app.com', 'user@app.com'], + 'android.intent.extra.BCC': ['liam@me.abc', 'abel@me.com'], + }, + package: 'com.google.android.gm', + type: 'message/rfc822', + ); + intent.launch(); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -191,7 +206,7 @@ class ExplicitIntentsWidget extends StatelessWidget { title: const Text('Test explicit intents'), ), body: Center( - child: Padding( + child: SingleChildScrollView( padding: const EdgeInsets.symmetric(vertical: 15.0), child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, @@ -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', + ), + ), ], ), ), diff --git a/packages/android_intent_plus/lib/android_intent.dart b/packages/android_intent_plus/lib/android_intent.dart index 6b09675a5f..3626a3a43d 100644 --- a/packages/android_intent_plus/lib/android_intent.dart +++ b/packages/android_intent_plus/lib/android_intent.dart @@ -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. @@ -34,6 +36,7 @@ class AndroidIntent { this.category, this.data, this.arguments, + this.arrayArguments, this.package, this.componentName, Platform? platform, @@ -54,6 +57,7 @@ class AndroidIntent { this.category, this.data, this.arguments, + this.arrayArguments, this.package, this.componentName, this.type, @@ -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? 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>? 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). @@ -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, diff --git a/packages/android_intent_plus/pubspec.yaml b/packages/android_intent_plus/pubspec.yaml index a157f7c324..bd3d12689f 100644 --- a/packages/android_intent_plus/pubspec.yaml +++ b/packages/android_intent_plus/pubspec.yaml @@ -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/