|
7 | 7 | import android.provider.Settings; |
8 | 8 | import android.text.TextUtils; |
9 | 9 | import android.util.Log; |
| 10 | + |
10 | 11 | import androidx.annotation.NonNull; |
11 | 12 | import androidx.annotation.Nullable; |
| 13 | + |
| 14 | +import java.util.ArrayList; |
| 15 | +import java.util.Map; |
| 16 | + |
12 | 17 | import io.flutter.plugin.common.BinaryMessenger; |
13 | 18 | import io.flutter.plugin.common.MethodCall; |
14 | 19 | import io.flutter.plugin.common.MethodChannel; |
15 | 20 | import io.flutter.plugin.common.MethodChannel.MethodCallHandler; |
16 | 21 | import io.flutter.plugin.common.MethodChannel.Result; |
17 | | -import java.util.ArrayList; |
18 | | -import java.util.Map; |
19 | 22 |
|
20 | 23 | /** Forwards incoming {@link MethodCall}s to {@link IntentSender#send}. */ |
21 | 24 | public final class MethodCallHandlerImpl implements MethodCallHandler { |
@@ -77,6 +80,8 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { |
77 | 80 | String category = call.argument("category"); |
78 | 81 | Uri data = call.argument("data") != null ? Uri.parse((String) call.argument("data")) : null; |
79 | 82 | Bundle arguments = convertArguments((Map<String, ?>) call.argument("arguments")); |
| 83 | + Bundle arrayArguments = convertArrayArguments((Map<String, ?>) call.argument("arrayArguments")); |
| 84 | + arguments.putAll(arrayArguments); |
80 | 85 | String packageName = call.argument("package"); |
81 | 86 | ComponentName componentName = |
82 | 87 | (!TextUtils.isEmpty(packageName) |
@@ -166,6 +171,51 @@ private static Bundle convertArguments(Map<String, ?> arguments) { |
166 | 171 | return bundle; |
167 | 172 | } |
168 | 173 |
|
| 174 | + private static Bundle convertArrayArguments(Map<String, ?> arrayArguments) { |
| 175 | + Bundle bundle = new Bundle(); |
| 176 | + if (arrayArguments == null) { |
| 177 | + return bundle; |
| 178 | + } |
| 179 | + for (String key : arrayArguments.keySet()) { |
| 180 | + Object value = arrayArguments.get(key); |
| 181 | + if (isTypedArrayList(value, Boolean.class)) { |
| 182 | + ArrayList<Boolean> list = (ArrayList<Boolean>) value; |
| 183 | + boolean[] array = new boolean[list.size()]; |
| 184 | + for (int i = 0; i < list.size(); i++) { |
| 185 | + array[i] = list.get(i); |
| 186 | + } |
| 187 | + bundle.putBooleanArray(key, array); |
| 188 | + } else if (isTypedArrayList(value, Integer.class)) { |
| 189 | + ArrayList<Integer> list = (ArrayList<Integer>) value; |
| 190 | + int[] array = new int[list.size()]; |
| 191 | + for (int i = 0; i < list.size(); i++) { |
| 192 | + array[i] = list.get(i); |
| 193 | + } |
| 194 | + bundle.putIntArray(key, array); |
| 195 | + } else if (isTypedArrayList(value, Long.class)) { |
| 196 | + ArrayList<Long> list = (ArrayList<Long>) value; |
| 197 | + long[] array = new long[list.size()]; |
| 198 | + for (int i = 0; i < list.size(); i++) { |
| 199 | + array[i] = list.get(i); |
| 200 | + } |
| 201 | + bundle.putLongArray(key, array); |
| 202 | + } else if (isTypedArrayList(value, Double.class)) { |
| 203 | + ArrayList<Double> list = (ArrayList<Double>) value; |
| 204 | + double[] array = new double[list.size()]; |
| 205 | + for (int i = 0; i < list.size(); i++) { |
| 206 | + array[i] = list.get(i); |
| 207 | + } |
| 208 | + bundle.putDoubleArray(key, array); |
| 209 | + } else if (isTypedArrayList(value, String.class)) { |
| 210 | + ArrayList<String> list = (ArrayList<String>) value; |
| 211 | + bundle.putStringArray(key, list.toArray(new String[list.size()])); |
| 212 | + } else { |
| 213 | + throw new UnsupportedOperationException("Unsupported type " + value); |
| 214 | + } |
| 215 | + } |
| 216 | + return bundle; |
| 217 | + } |
| 218 | + |
169 | 219 | private static boolean isTypedArrayList(Object value, Class<?> type) { |
170 | 220 | if (!(value instanceof ArrayList)) { |
171 | 221 | return false; |
|
0 commit comments