Archived: this has moved to https://github.com/project-robius/robius
This crate provides easy Rust interfaces to open URIs across multiple platforms, including:
- macOS (via
NSWorkspace
) - Android (via
android/content/Intent
) - Linux (via
xdg-open
) - Windows (via
start
) - iOS (via
UIApplication
)
URIs take many different forms: URLs (http://
), tel:
, mailto:
, file://
, and more (see the official list of schemes).
use robius_open::Uri;
Uri::new("tel:+61 123 456 789")
.open()
.expect("failed to open telephone URI");
use robius_open::Uri;
Uri::new("http://www.google.com")
.open_with_completion(|success| {
log!("Opened URI? {success}");
})
.expect("failed to open URL");
To use this crate on Android with the default android-result
feature enabled,
you must add the following to your app manifest:
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
<queries>
<intent>
<action android:name="android.intent.action.MAIN" />
</intent>
</queries>
Alternatively, you can omit those permissions if you disable the android-result
feature,
but that will then cause Uri::open()
to always return Ok
(and the on_completion
closure to always receive a success value of true
)
regardless of whether the URI was actually opened successfully.