1515import io .flutter .plugin .common .MethodChannel .MethodCallHandler ;
1616import io .flutter .plugin .common .MethodChannel .Result ;
1717import java .util .ArrayList ;
18+ import java .util .HashMap ;
1819import java .util .Map ;
1920
2021/** Forwards incoming {@link MethodCall}s to {@link IntentSender#send}. */
@@ -75,14 +76,19 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
7576 String action = convertAction ((String ) call .argument ("action" ));
7677 Integer flags = call .argument ("flags" );
7778 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 );
8083 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+ }
8692 String type = call .argument ("type" );
8793
8894 Intent intent =
@@ -128,6 +134,9 @@ private static Bundle convertArguments(Map<String, ?> arguments) {
128134 }
129135 for (String key : arguments .keySet ()) {
130136 Object value = arguments .get (key );
137+ ArrayList <String > stringArrayList = isStringArrayList (value );
138+ ArrayList <Integer > integerArrayList = isIntegerArrayList (value );
139+ Map <String , ?> stringMap = isStringKeyedMap (value );
131140 if (value instanceof Integer ) {
132141 bundle .putInt (key , (Integer ) value );
133142 } else if (value instanceof String ) {
@@ -146,42 +155,67 @@ private static Bundle convertArguments(Map<String, ?> arguments) {
146155 bundle .putLongArray (key , (long []) value );
147156 } else if (value instanceof double []) {
148157 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 ));
155164 } else {
156165 throw new UnsupportedOperationException ("Unsupported type " + value );
157166 }
158167 }
159168 return bundle ;
160169 }
161170
162- private static boolean isTypedArrayList (Object value , Class <?> type ) {
171+ private static ArrayList <Integer > isIntegerArrayList (Object value ) {
172+ ArrayList <Integer > integerArrayList = new ArrayList <>();
163173 if (!(value instanceof ArrayList )) {
164- return false ;
174+ return null ;
165175 }
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 );
170182 }
171183 }
172- return true ;
184+ return integerArrayList ;
173185 }
174186
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 <>();
176205 if (!(value instanceof Map )) {
177- return false ;
206+ return null ;
178207 }
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+ }
183217 }
184218 }
185- return true ;
219+ return stringMap ;
186220 }
187221}
0 commit comments