Skip to content
Draft
Show file tree
Hide file tree
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
38 changes: 36 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
## 0.0.1
# Changelog

* TODO: Describe initial release.
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.2] - 2024-09-08

### Added
- Comprehensive dartdoc documentation for all public APIs
- Detailed README with usage examples and API reference
- MIT License
- Better error handling and method signatures
- Support for notification actions and remote input

### Changed
- Improved code style and consistency
- Removed debug print statements from production code
- Fixed inconsistent Map initialization patterns
- Cleaned up commented code
- Improved toString() method formatting
- Updated example documentation

### Fixed
- Removed unnecessary 'new' keyword usage
- Fixed mixed language comments
- Improved code documentation and comments

## [0.0.1] - Initial Release

### Added
- Basic notification listening capability for Android
- Remote input support for replying to notifications
- Notification action triggering
- Platform channel communication setup
- Example application demonstrating core features
22 changes: 21 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
TODO: Add your license here.
MIT License

Copyright (c) 2024 Remote Input Plugin Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
182 changes: 172 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,177 @@
# remote_input
# Remote Input Plugin

A new flutter plugin project.
A Flutter plugin that provides notification listener capabilities with remote input functionality for Android applications. This plugin allows your Flutter app to listen to incoming notifications and interact with them, including replying to notifications that support remote input.

## Getting Started
## Features

This project is a starting point for a Flutter
[plug-in package](https://flutter.dev/developing-packages/),
a specialized package that includes platform-specific implementation code for
Android and/or iOS.
- 🔔 Listen to incoming Android notifications in real-time
- 💬 Reply to notifications that support remote input (e.g., messaging apps)
- ⚡ Trigger notification actions programmatically
- 📱 Get available actions for notifications
- 🎯 Filter and process notification events

For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
## Platform Support

| Platform | Support |
|----------|---------|
| Android | ✅ Full support |
| iOS | ❌ Not supported |

## Installation

Add this to your package's `pubspec.yaml` file:

```yaml
dependencies:
remote_input: ^0.0.2
```

Run the following command to install the package:

```bash
flutter pub get
```

## Permissions

This plugin requires notification access permission on Android. The user must manually enable notification access for your app in the device settings.

### Android Setup

Add the following permission to your `android/app/src/main/AndroidManifest.xml`:

```xml
<uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" />
```

## Usage

### Basic Example

```dart
import 'package:remote_input/remote_input.dart';
import 'dart:async';

class NotificationListener {
late RemoteInput _remoteInput;
late StreamSubscription<NotificationEvent> _subscription;

void startListening() {
_remoteInput = RemoteInput();

try {
_subscription = _remoteInput.notificationStream.listen((event) {
print('Received notification from: ${event.packageName}');
print('Title: ${event.packageTitle}');
print('Message: ${event.packageMessage}');
print('Supports reply: ${event.withRemoteInput}');
});
} on NotificationException catch (e) {
print('Error: $e');
}
}

void stopListening() {
_subscription.cancel();
}
}
```

### Replying to Notifications

```dart
// Reply to a notification that supports remote input
void replyToNotification(String notificationId, String replyText) async {
try {
bool success = await RemoteInput.remoteReply(replyText, notificationId);
if (success) {
print('Reply sent successfully');
} else {
print('Failed to send reply');
}
} catch (e) {
print('Error sending reply: $e');
}
}
```

### Triggering Notification Actions

```dart
// Get available actions for a notification
void getNotificationActions(String notificationId) async {
List<String> actions = await RemoteInput.getNotificationActions(notificationId);
print('Available actions: $actions');
}

// Trigger a specific action
void triggerAction(String notificationId, int actionIndex) async {
bool success = await RemoteInput.triggerAction(notificationId, actionIndex);
if (success) {
print('Action triggered successfully');
}
}
```

## API Reference

### Classes

#### `RemoteInput`
Main class providing notification listening and interaction capabilities.

**Static Methods:**
- `Future<String> get platformVersion` - Gets the platform version
- `Future<bool> remoteReply(String text, String id)` - Sends a reply to a notification
- `Future<bool> triggerAction(String notificationId, int actionIndex)` - Triggers a notification action
- `Future<List<String>> getNotificationActions(String notificationId)` - Gets available actions

**Instance Properties:**
- `Stream<NotificationEvent> get notificationStream` - Stream of incoming notifications

#### `NotificationEvent`
Represents a notification event with all relevant data.

**Properties:**
- `String id` - Unique notification identifier
- `String packageName` - Source app package name
- `String packageTitle` - Notification title
- `String packageMessage` - Notification message content
- `bool withRemoteInput` - Whether the notification supports replies
- `String? remoteInputSymbol` - Remote input symbol/hint
- `List<NotificationAction> actions` - Available actions

#### `NotificationAction`
Represents an action available on a notification.

**Properties:**
- `int index` - Action index
- `String title` - Action title/label

#### `NotificationException`
Exception thrown when notification operations fail.

## Example App

See the [example](example/) directory for a complete demonstration of the plugin's capabilities, including:

- Setting up notification listening
- Displaying incoming notifications
- Replying to notifications
- Managing notification actions

## Important Notes

1. **Permissions**: Users must manually grant notification access permission in Android settings
2. **Android Only**: This plugin only works on Android devices
3. **Background Processing**: Consider the app's lifecycle when implementing notification listening
4. **Testing**: Use real messaging apps to test remote input functionality

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

77 changes: 67 additions & 10 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,73 @@
# remote_input_example
# Remote Input Plugin Example

Demonstrates how to use the remote_input plugin.
This example demonstrates how to use the `remote_input` plugin to listen to Android notifications and interact with them.

## Getting Started
## Features Demonstrated

This project is a starting point for a Flutter application.
- 📱 **Notification Listening**: Real-time monitoring of incoming notifications
- 💬 **Remote Replies**: Send replies to notifications that support it (e.g., messaging apps)
- ⚡ **Action Triggering**: Execute notification actions programmatically
- 🎯 **Event Filtering**: Process and display notification data

A few resources to get you started if this is your first Flutter project:
## Setup

- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)
1. **Grant Notification Access**:
- Go to Settings > Apps > [Your App] > Permissions
- Enable "Notification access" for this app
- This is required for the plugin to work

For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
2. **Run the Example**:
```bash
flutter run
```

## How to Use

1. **Start Listening**: Tap the play button to begin monitoring notifications
2. **Receive Notifications**: Send yourself messages from apps like WhatsApp, Telegram, or SMS
3. **View Events**: See incoming notifications listed in the app
4. **Reply**: Tap the reply icon on notifications that support remote input
5. **Stop Listening**: Tap the stop button to pause monitoring

## Code Structure

- `main.dart`: Contains the main application logic
- `MyApp`: Main app widget with notification stream handling
- `ReplyDialog`: Dialog for composing replies to notifications

## Key Components

### Notification Stream
```dart
_subscription = _remoteInput.notificationStream.listen(onData);
```

### Reply Functionality
```dart
RemoteInput.remoteReply(textEditingController.text, id)
```

### Event Processing
```dart
void onData(NotificationEvent event) {
setState(() {
_log.add(event);
});
}
```

## Testing

To test the example:

1. Install messaging apps (WhatsApp, Telegram, etc.)
2. Start the example app and begin listening
3. Send yourself messages from another device
4. Observe notifications appearing in the app
5. Try replying to supported notifications

## Requirements

- Android device (iOS not supported)
- Notification access permission
- Messaging apps for testing remote input functionality
Loading