15
15
import io .flutter .plugin .common .MethodChannel .MethodCallHandler ;
16
16
import io .flutter .plugin .common .MethodChannel .Result ;
17
17
import java .util .ArrayList ;
18
+ import java .util .HashMap ;
18
19
import java .util .Map ;
19
20
20
21
/** Forwards incoming {@link MethodCall}s to {@link IntentSender#send}. */
@@ -75,14 +76,19 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
75
76
String action = convertAction ((String ) call .argument ("action" ));
76
77
Integer flags = call .argument ("flags" );
77
78
String category = call .argument ("category" );
78
- Uri data = call .argument ("data" ) != null ? Uri .parse ((String ) call .argument ("data" )) : null ;
79
- Bundle arguments = convertArguments ((Map <String , ?>) call .argument ("arguments" ));
79
+ String stringData = call .argument ("data" );
80
+ Uri data = call .argument ("data" ) != null ? Uri .parse (stringData ) : null ;
81
+ Map <String , ?> stringMap = call .argument ("arguments" );
82
+ Bundle arguments = convertArguments (stringMap );
80
83
String packageName = call .argument ("package" );
81
- ComponentName componentName =
82
- (!TextUtils .isEmpty (packageName )
83
- && !TextUtils .isEmpty ((String ) call .argument ("componentName" )))
84
- ? new ComponentName (packageName , (String ) call .argument ("componentName" ))
85
- : null ;
84
+ String component = call .argument ("componentName" );
85
+ ComponentName componentName = null ;
86
+ if (packageName != null
87
+ && component != null
88
+ && !TextUtils .isEmpty (packageName )
89
+ && !TextUtils .isEmpty (component )) {
90
+ componentName = new ComponentName (packageName , component );
91
+ }
86
92
String type = call .argument ("type" );
87
93
88
94
Intent intent =
@@ -128,6 +134,9 @@ private static Bundle convertArguments(Map<String, ?> arguments) {
128
134
}
129
135
for (String key : arguments .keySet ()) {
130
136
Object value = arguments .get (key );
137
+ ArrayList <String > stringArrayList = isStringArrayList (value );
138
+ ArrayList <Integer > integerArrayList = isIntegerArrayList (value );
139
+ Map <String , ?> stringMap = isStringKeyedMap (value );
131
140
if (value instanceof Integer ) {
132
141
bundle .putInt (key , (Integer ) value );
133
142
} else if (value instanceof String ) {
@@ -146,42 +155,67 @@ private static Bundle convertArguments(Map<String, ?> arguments) {
146
155
bundle .putLongArray (key , (long []) value );
147
156
} else if (value instanceof double []) {
148
157
bundle .putDoubleArray (key , (double []) value );
149
- } else if (isTypedArrayList ( value , Integer . class ) ) {
150
- bundle .putIntegerArrayList (key , ( ArrayList < Integer >) value );
151
- } else if (isTypedArrayList ( value , String . class ) ) {
152
- bundle .putStringArrayList (key , ( ArrayList < String >) value );
153
- } else if (isStringKeyedMap ( value ) ) {
154
- bundle .putBundle (key , convertArguments (( Map < String , ?>) value ));
158
+ } else if (integerArrayList != null ) {
159
+ bundle .putIntegerArrayList (key , integerArrayList );
160
+ } else if (stringArrayList != null ) {
161
+ bundle .putStringArrayList (key , stringArrayList );
162
+ } else if (stringMap != null ) {
163
+ bundle .putBundle (key , convertArguments (stringMap ));
155
164
} else {
156
165
throw new UnsupportedOperationException ("Unsupported type " + value );
157
166
}
158
167
}
159
168
return bundle ;
160
169
}
161
170
162
- private static boolean isTypedArrayList (Object value , Class <?> type ) {
171
+ private static ArrayList <Integer > isIntegerArrayList (Object value ) {
172
+ ArrayList <Integer > integerArrayList = new ArrayList <>();
163
173
if (!(value instanceof ArrayList )) {
164
- return false ;
174
+ return null ;
165
175
}
166
- ArrayList list = (ArrayList ) value ;
167
- for (Object o : list ) {
168
- if (!(o == null || type .isInstance (o ))) {
169
- return false ;
176
+ ArrayList <?> intList = (ArrayList <?>) value ;
177
+ for (Object o : intList ) {
178
+ if (!(o instanceof Integer )) {
179
+ return null ;
180
+ } else {
181
+ integerArrayList .add ((Integer ) o );
170
182
}
171
183
}
172
- return true ;
184
+ return integerArrayList ;
173
185
}
174
186
175
- private static boolean isStringKeyedMap (Object value ) {
187
+ private static ArrayList <String > isStringArrayList (Object value ) {
188
+ ArrayList <String > stringArrayList = new ArrayList <>();
189
+ if (!(value instanceof ArrayList )) {
190
+ return null ;
191
+ }
192
+ ArrayList <?> stringList = (ArrayList <?>) value ;
193
+ for (Object o : stringList ) {
194
+ if (!(o instanceof String )) {
195
+ return null ;
196
+ } else {
197
+ stringArrayList .add ((String ) o );
198
+ }
199
+ }
200
+ return stringArrayList ;
201
+ }
202
+
203
+ private static Map <String , ?> isStringKeyedMap (Object value ) {
204
+ Map <String , Object > stringMap = new HashMap <>();
176
205
if (!(value instanceof Map )) {
177
- return false ;
206
+ return null ;
178
207
}
179
- Map map = (Map ) value ;
180
- for (Object key : map .keySet ()) {
181
- if (!(key == null || key instanceof String )) {
182
- return false ;
208
+ Map <?, ?> mapValue = (Map <?, ?>) value ;
209
+ for (Object key : mapValue .keySet ()) {
210
+ if (!(key instanceof String )) {
211
+ return null ;
212
+ } else {
213
+ Object o = mapValue .get (key );
214
+ if (o != null ) {
215
+ stringMap .put ((String ) key , o );
216
+ }
183
217
}
184
218
}
185
- return true ;
219
+ return stringMap ;
186
220
}
187
221
}
0 commit comments