Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android_intent_plus): adds error catching and forwarding #3452

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -73,56 +73,61 @@ void stopListening() {
*/
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
String action = convertAction((String) call.argument("action"));
Integer flags = call.argument("flags");
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)
&& !TextUtils.isEmpty((String) call.argument("componentName")))
? new ComponentName(packageName, (String) call.argument("componentName"))
: null;
String type = call.argument("type");
try {
String action = convertAction((String) call.argument("action"));
Integer flags = call.argument("flags");
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)
&& !TextUtils.isEmpty((String) call.argument("componentName")))
? new ComponentName(packageName, (String) call.argument("componentName"))
: null;
String type = call.argument("type");

Intent intent =
sender.buildIntent(
action, flags, category, data, arguments, packageName, componentName, type);
Intent intent =
sender.buildIntent(
action, flags, category, data, arguments, packageName, componentName, type);

if ("parseAndLaunch".equalsIgnoreCase(call.method)) {
try {
intent = sender.parse(call.argument("uri"));
sender.send(intent);
result.success(null);
} catch (URISyntaxException e) {
result.error("parse_error", "Failed to parse URI", e.getMessage());
}
} else if ("launch".equalsIgnoreCase(call.method)) {

if (intent != null && !sender.canResolveActivity(intent)) {
Log.i(TAG, "Cannot resolve explicit intent, falling back to implicit");
intent.setPackage(null);
}

if ("parseAndLaunch".equalsIgnoreCase(call.method)) {
try {
intent = sender.parse(call.argument("uri"));
sender.send(intent);
result.success(null);
} catch (URISyntaxException e) {
result.error("parse_error", "Failed to parse URI", e.getMessage());
}
} else if ("launch".equalsIgnoreCase(call.method)) {
} else if ("launchChooser".equalsIgnoreCase(call.method)) {
String title = call.argument("chooserTitle");

if (intent != null && !sender.canResolveActivity(intent)) {
Log.i(TAG, "Cannot resolve explicit intent, falling back to implicit");
intent.setPackage(null);
sender.launchChooser(intent, title);
result.success(null);
} else if ("sendBroadcast".equalsIgnoreCase(call.method)) {
sender.sendBroadcast(intent);
result.success(null);
} else if ("canResolveActivity".equalsIgnoreCase(call.method)) {
result.success(sender.canResolveActivity(intent));
} else if ("getResolvedActivity".equalsIgnoreCase(call.method)) {
result.success(sender.getResolvedActivity(intent));
} else {
result.notImplemented();
}

sender.send(intent);
result.success(null);
} else if ("launchChooser".equalsIgnoreCase(call.method)) {
String title = call.argument("chooserTitle");

sender.launchChooser(intent, title);
result.success(null);
} else if ("sendBroadcast".equalsIgnoreCase(call.method)) {
sender.sendBroadcast(intent);
result.success(null);
} else if ("canResolveActivity".equalsIgnoreCase(call.method)) {
result.success(sender.canResolveActivity(intent));
} else if ("getResolvedActivity".equalsIgnoreCase(call.method)) {
result.success(sender.getResolvedActivity(intent));
} else {
result.notImplemented();
} catch (Throwable e) {
result.error("error", e.getMessage(), null);
}
}

Expand Down