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

feature: add option to send arguments via intent #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
} else if (call.method.equals("openApp")) {

String packageName = call.argument("package_name");
String arguments = call.argument("arguments").toString();

result.success(openApp(packageName, call.argument("open_store").toString()));
if(arguments != null)
result.success(openApp(packageName, call.argument("open_store").toString(), arguments));
else
result.success(openApp(packageName, call.argument("open_store").toString()));

} else {
result.notImplemented();
Expand Down Expand Up @@ -94,4 +98,27 @@ private String openApp(String packageName, String openStore) {
}
return "something went wrong";
}

private String openApp(String packageName, String openStore, String arguments) {
if (isAppInstalled(packageName)) {
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);
if (launchIntent != null) {
// null pointer check in case package name was not found
launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
launchIntent.putExtra("arguments", arguments);
context.startActivity(launchIntent);
return "app_opened";
}
} else {
if (openStore != "false") {
Intent intent1 = new Intent(Intent.ACTION_VIEW);
intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent1.setData(android.net.Uri.parse("https://play.google.com/store/apps/details?id=" + packageName));
context.startActivity(intent1);
return "navigated_to_store";
}
}
return "something went wrong";
}

}
7 changes: 5 additions & 2 deletions lib/external_app_launcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class LaunchApp {
{String? iosUrlScheme,
String? androidPackageName,
String? appStoreLink,
bool? openStore}) async {
bool? openStore,
String? arguments,
}) async {
String? packageName = Platform.isIOS ? iosUrlScheme : androidPackageName;
String packageVariableName =
Platform.isIOS ? 'iosUrlScheme' : 'androidPackageName';
Expand All @@ -46,7 +48,8 @@ class LaunchApp {
return await _channel.invokeMethod('openApp', {
'package_name': packageName,
'open_store': openStore == false ? "false" : "open it",
'app_store_link': appStoreLink
'app_store_link': appStoreLink,
'arguments' : arguments,
}).then((value) {
if (value == "app_opened") {
print("app opened successfully");
Expand Down