tauri-plugin-intent
tauri-plugin-intent — это плагин для Tauri, который позволяет работать с Android Intent и открывать системные обработчики на десктопных платформах.
Tauri Plugin Intent
A Tauri plugin for opening Android Intents and system default handlers on desktop platforms.
Features
- Android Intent Support: Open Android intents with full parameter support
- Cross-platform: Fallback to system default handlers on desktop platforms
- TypeScript Support: Full TypeScript definitions and convenience functions
- Multiple Intent Types: Support for VIEW, SEND, CALL and other intent actions
- Extras Support: Pass complex data through intent extras
- Framework Integration: Works with any Tauri frontend framework (React, Vue, Svelte, Leptos, etc.)
Installation
1. Add the plugin to your Cargo.toml:
[]
= { = "https://github.com/your-repo/tauri-plugin-intent" }
2. Initialize the plugin in your Tauri app:
3. Add permissions to your capabilities:
Usage
JavaScript/TypeScript API
Install the npm package (if using separate package):
Basic Usage
import { openIntent, openPhoneDialer, openUrl, sendEmail } from '@tauri-apps/plugin-intent';
// Open phone dialer
await openPhoneDialer('+1234567890');
// Open URL
await openUrl('https://example.com');
// Send email
await sendEmail({
to: ['recipient@example.com'],
subject: 'Hello',
body: 'This is a test email'
});
// Custom intent
await openIntent({
action: 'android.intent.action.VIEW',
data: 'tel:+1234567890',
flags: ['FLAG_ACTIVITY_NEW_TASK']
});
Advanced Usage with Extras
// Send SMS with custom message
await openIntent({
action: 'android.intent.action.VIEW',
data: 'sms:+1234567890',
extras: {
'sms_body': 'Hello from Tauri!'
}
});
// Share content
await openIntent({
action: 'android.intent.action.SEND',
mimeType: 'text/plain',
extras: {
'android.intent.extra.TEXT': 'Check out this awesome app!',
'android.intent.extra.SUBJECT': 'Amazing Discovery'
}
});
Rust API
use IntentExt;
async
Framework Integration
Leptos Integration
For Leptos applications, you can use the JavaScript API with wasm-bindgen and serde-wasm-bindgen:
Add dependencies to your Cargo.toml:
[]
= { = "0.8", = ["csr"] }
= { = "1", = ["derive"] }
= "1"
= "0.6"
= "0.2"
= "0.3"
Example Leptos component:
use spawn_local;
use ;
use ;
use *;
extern "C"
React/Next.js Integration
import { openPhoneDialer } from '@tauri-apps/plugin-intent';
function PhoneDialer() {
const [phoneNumber, setPhoneNumber] = useState('');
const [message, setMessage] = useState('');
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
try {
const result = await openPhoneDialer(phoneNumber);
if (result.success) {
setMessage('Phone dialer opened successfully!');
} else {
setMessage(`Error: ${result.error}`);
}
} catch (error) {
setMessage(`Failed to open dialer: ${error}`);
}
};
return (
<form onSubmit={handleSubmit}>
<input
type="tel"
value={phoneNumber}
onChange={(e) => setPhoneNumber(e.target.value)}
placeholder="Enter phone number..."
/>
<button type="submit">Open Dialer</button>
{message && <p>{message}</p>}
</form>
);
}
Supported Intent Actions
Android
android.intent.action.VIEW- Open URLs, phone numbers, etc.android.intent.action.SEND- Send content to other appsandroid.intent.action.CALL- Initiate phone callsandroid.intent.action.SENDTO- Send to specific targetsandroid.intent.action.DIAL- Open phone dialerandroid.intent.action.EDIT- Edit content- Custom actions supported
Desktop Fallback
android.intent.action.VIEW- Opens URLs with system default handler- Other actions return appropriate error messages
Intent Parameters
| Parameter | Type | Description |
|---|---|---|
action |
string |
The intent action (required) |
data |
string? |
The intent data URI |
category |
string? |
Intent category |
mimeType |
string? |
MIME type for the intent |
packageName |
string? |
Target package name |
className |
string? |
Target class name |
flags |
string[]? |
Intent flags |
extras |
Record<string, any>? |
Additional data |
Supported Intent Flags
FLAG_ACTIVITY_NEW_TASKFLAG_ACTIVITY_CLEAR_TOPFLAG_ACTIVITY_CLEAR_TASKFLAG_ACTIVITY_SINGLE_TOPFLAG_ACTIVITY_NO_HISTORYFLAG_ACTIVITY_MULTIPLE_TASK
Common Use Cases
Phone and SMS
// Open phone dialer
await openIntent({
action: 'android.intent.action.VIEW',
data: 'tel:+1234567890'
});
// Send SMS
await openIntent({
action: 'android.intent.action.VIEW',
data: 'sms:+1234567890',
extras: { 'sms_body': 'Hello!' }
});
// Make a phone call (requires CALL_PHONE permission)
await openIntent({
action: 'android.intent.action.CALL',
data: 'tel:+1234567890'
});
Web and Maps
// Open website
await openUrl('https://example.com');
// Open location in maps
await openIntent({
action: 'android.intent.action.VIEW',
data: 'geo:37.7749,-122.4194?q=San+Francisco'
});
// Open maps with specific app
await openIntent({
action: 'android.intent.action.VIEW',
data: 'google.navigation:q=San+Francisco',
packageName: 'com.google.android.apps.maps'
});
Email and Sharing
// Send email using mailto
await openIntent({
action: 'android.intent.action.VIEW',
data: 'mailto:test@example.com?subject=Hello&body=Message'
});
// Share text
await openIntent({
action: 'android.intent.action.SEND',
mimeType: 'text/plain',
extras: {
'android.intent.extra.TEXT': 'Check this out!',
'android.intent.extra.SUBJECT': 'Amazing Content'
}
});
// Share image (Android)
await openIntent({
action: 'android.intent.action.SEND',
mimeType: 'image/*',
extras: {
'android.intent.extra.STREAM': 'file:///path/to/image.jpg'
}
});
Error Handling
All functions return a Promise<OpenIntentResponse>:
interface OpenIntentResponse {
success: boolean;
error?: string;
}
Always check the success field:
const result = await openPhoneDialer('+1234567890');
if (!result.success) {
console.error('Failed to open dialer:', result.error);
// Handle error appropriately
}
Platform Support
- ✅ Android (Full intent support)
- ✅ iOS (Limited support via system handlers)
- ✅ Windows (System default handlers)
- ✅ macOS (System default handlers)
- ✅ Linux (System default handlers)
Android Permissions
For certain intents, you may need to add permissions to your AndroidManifest.xml:
<!-- For phone calls -->
<!-- For sending SMS -->
<!-- For camera access -->
<!-- For location access -->
Development
Running the Example
The plugin includes a Leptos example demonstrating various intent operations:
Building the Plugin
# Build Rust code
# Build JavaScript/TypeScript API
# Run tests
Project Structure
tauri-plugin-intent/
├── src/ # Rust plugin code
├── android/ # Android-specific implementation
├── guest-js/ # JavaScript/TypeScript API
├── examples/ # Example applications
│ └── leptos-example/ # Leptos integration example
├── permissions/ # Plugin permissions
└── README.md # This file
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Troubleshooting
Command not found errors
Ensure you have:
- Added the plugin to your
Cargo.toml - Initialized the plugin in your
main.rs - Added
intent:defaultto your capabilities - Rebuilt your application after adding the plugin
Intent not opening on Android
- Check that the target application is installed
- Verify the intent action and data format
- Ensure required permissions are added to
AndroidManifest.xml - Check Android logs:
adb logcat | grep Intent
Desktop limitations
Desktop platforms have limited intent support:
- Only
android.intent.action.VIEWwith URLs is supported - Other actions will return error messages
- Use platform-specific APIs for advanced desktop integration
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built with Tauri
- Inspired by Android's Intent system
- Thanks to the Tauri community for feedback and contributions