A NativePHP Mobile plugin for communicating with device functionalities like the browser, phone dialer, SMS, map apps, and deep linking schemes.
Similar to Flutter's url_launcher, but tailored for NativePHP mobile.
Browser functionalities are already provided by NativePHP, so this plugin is only for other functionalities, for browser functionalities use NativePHP Mobile Borwser
- PHP 8.2+
- Laravel 11+
- NativePHP Mobile ^3.0
composer require rajen/nativephp-url-launcherPublish the configuration file:
php artisan vendor:publish --tag="nativephp-url-launcher-config"The plugin exposes a Laravel Facade, making it extremely easy to use:
use Rajen\UrlLauncher\Facades\UrlLauncher;
// Send an email
UrlLauncher::openEmail('hello@nativephp.com', 'Support Request', 'Hello from my app!');
// Dial a phone number
UrlLauncher::openPhone('+1234567890');
// Send an SMS
UrlLauncher::openSms('+1234567890', 'Please reply to this message.');
// Open WhatsApp
UrlLauncher::openWhatsApp('+1234567890', 'Hello!');
// Open Maps
UrlLauncher::openMap('London, UK');
// Open custom app deep link
UrlLauncher::openCustomScheme('myapp://product/123');
// Check if a URL can be launched
if (UrlLauncher::canLaunch('twitter://user?screen_name=NativePHP')) {
UrlLauncher::launch('twitter://user?screen_name=NativePHP');
}If your app needs to trigger external deep links (e.g. twitter://, whatsapp://) or needs to handle returns back into your app via Custom Schemes (myapp://), you must configure the native project manifests.
Add the following <queries> to your manifest if you are targeting Android 11+ to canLaunch other apps:
<manifest package="com.your.app">
<queries>
<!-- For WhatsApp -->
<package android:name="com.whatsapp" />
<!-- For Emails -->
<intent>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
</intent>
<!-- For Custom apps -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="twitter" />
</intent>
</queries>
</manifest>For iOS, you need to whitelist URL schemes your app wants to open using LSApplicationQueriesSchemes.
Add this to your Info.plist:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
<string>twitter</string>
<string>mailto</string>
<string>tel</string>
<string>sms</string>
</array>You can listen to URL Launcher events using standard Laravel Event listeners:
Rajen\UrlLauncher\Events\UrlLaunchedRajen\UrlLauncher\Events\UrlLaunchFailedRajen\UrlLauncher\Events\DeepLinkReceivedRajen\UrlLauncher\Events\UrlLaunchCompletedIlluminate\Support\Facades\Event
Example:
use Rajen\UrlLauncher\Events\UrlLaunched;
use Rajen\UrlLauncher\Events\UrlLaunchFailed;
use Rajen\UrlLauncher\Events\DeepLinkReceived;
use Rajen\UrlLauncher\Events\UrlLaunchCompleted;
use Illuminate\Support\Facades\Event;
Event::listen(function (DeepLinkReceived $event) {
// do something
});MIT
For questions, feature requests, or issues, please contact laravel.rajen@gmail.com.