Skip to content

Commit 10ddabb

Browse files
authored
Merge pull request #2 from DevsOnFlutter/dev
v0.0.1
2 parents f3b66e4 + cf23fde commit 10ddabb

33 files changed

+1115
-169
lines changed

Diff for: .idea/libraries/Dart_SDK.xml

+20-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/runConfigurations.xml

-10
This file was deleted.

Diff for: CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
## 0.0.1
1+
## v0.0.1
22

3-
* TODO: Describe initial release.
3+
* Initial Development Release

Diff for: README.md

+228-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Flutter plugin for notification read & reply.
44

5-
<img src="https://i.imgur.com/462Y6wf.gif" title="Flutter_Shortcuts"/>
5+
<img src="https://i.imgur.com/kz6uoXm.png" title="Flutter_Shortcuts"/>
66

77
![GitHub](https://img.shields.io/github/license/DevsOnFlutter/reflex?style=plastic) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/DevsOnFlutter/reflex?style=plastic) ![GitHub top language](https://img.shields.io/github/languages/top/DevsOnFlutter/reflex?style=plastic) ![GitHub language count](https://img.shields.io/github/languages/count/DevsOnFlutter/reflex?style=plastic) ![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/DevsOnFlutter/reflex?style=plastic) ![GitHub issues](https://img.shields.io/github/issues/DevsOnFlutter/reflex?style=plastic) ![GitHub Repo stars](https://img.shields.io/github/stars/DevsOnFlutter/reflex?style=social) ![GitHub forks](https://img.shields.io/github/forks/DevsOnFlutter/reflex?style=social)
88

@@ -42,7 +42,7 @@ dependencies:
4242
reflex: <latest version>
4343
```
4444
45-
Run pub get and get packages.
45+
Run `pub get` and get packages.
4646

4747
### Step 2: Add Service in `AndroidManifest.xml`
4848

@@ -61,7 +61,232 @@ Add the following service inside the `application` tag of `AndroidManifest.xml`.
6161
</application>
6262
```
6363

64-
### Step 3
64+
**Android 12+ Compatibility**
65+
Add `android:exported="true"` field in the service tag to make it compatible with Android 12+.
66+
67+
```xml
68+
...
69+
<service
70+
android:label="notifications"
71+
android:name="com.devsonflutter.reflex.notification.NotificationListener"
72+
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
73+
android:exported="true">
74+
<intent-filter>
75+
<action android:name="android.service.notification.NotificationListenerService" />
76+
</intent-filter>
77+
</service>
78+
</application>
79+
```
80+
81+
### Step 3: Instantiate Reflex
82+
83+
Reflex must only be instantiated only once.
84+
85+
```dart
86+
Reflex reflex = Reflex();
87+
```
88+
89+
90+
## Example
91+
92+
Go to example section in pub.dev to see the full example code.
93+
94+
In GitHub, head over to `example/lib/main.dart` to see the full example code.
95+
96+
### Import
97+
98+
This single import is enough for using reflex.
99+
100+
```dart
101+
import 'package:reflex/reflex.dart';
102+
```
103+
104+
### Listen & Reply
105+
106+
```dart
107+
StreamSubscription<ReflexEvent>? _subscription;
108+
final List<ReflexEvent> _notificationLogs = [];
109+
final List<ReflexEvent> _autoReplyLogs = [];
110+
bool isListening = false;
111+
112+
Reflex reflex = Reflex(
113+
debug: true,
114+
packageNameList: ["com.whatsapp", "com.tyup"],
115+
packageNameExceptionList: ["com.android.systemui"],
116+
autoReply: AutoReply(
117+
packageNameList: ["com.whatsapp"],
118+
message: "[Reflex] This is an automated reply.",
119+
),
120+
);
121+
122+
@override
123+
void initState() {
124+
super.initState();
125+
initPlatformState();
126+
}
127+
128+
Future<void> initPlatformState() async {
129+
startListening();
130+
}
131+
132+
void onData(ReflexEvent event) {
133+
setState(() {
134+
if (event.type == ReflexEventType.notification) {
135+
_notificationLogs.add(event);
136+
} else if (event.type == ReflexEventType.reply) {
137+
_autoReplyLogs.add(event);
138+
}
139+
});
140+
debugPrint(event.toString());
141+
}
142+
143+
void startListening() {
144+
try {
145+
_subscription = reflex.notificationStream!.listen(onData);
146+
setState(() {
147+
isListening = true;
148+
});
149+
} on ReflexException catch (exception) {
150+
debugPrint(exception.toString());
151+
}
152+
}
153+
154+
void stopListening() {
155+
_subscription?.cancel();
156+
setState(() => isListening = false);
157+
}
158+
```
159+
160+
## Quick Guide
161+
162+
A quick guide to **Flutter Reflex plugin**!
163+
164+
### Debugging
165+
166+
Debugging allows you to debug the plugin's functionality, logs are shown in the console.
167+
168+
By default debug logging is enabled. You can configure it using the debug field in the Reflex class.
169+
170+
171+
```dart
172+
Reflex reflex = Reflex(
173+
debug: false,
174+
);
175+
```
176+
177+
### Listen notification permission
178+
179+
See if listening notification permission has been granted or not.
180+
181+
```dart
182+
bool isPermissionGranted = await Reflex.isPermissionGranted;
183+
```
184+
185+
### Request notification listening permission
186+
187+
Use the function to grant notification listening permission.
188+
189+
```dart
190+
await Reflex.requestPermission();
191+
```
192+
193+
### Notification Stream
194+
195+
Use the reflex object to get a notification stream to listen to notifications in your flutter application.
196+
197+
```dart
198+
StreamSubscription<ReflexEvent>? _subscription;
199+
_subscription = reflex.notificationStream!.listen((event) {
200+
// Application Logic
201+
});
202+
```
203+
204+
The stream is subscribed for `ReflexEvent` whenever a notification is received.
205+
206+
#### Reflex Event
207+
208+
The incoming reflex event contains:
209+
210+
* **type**: `ReflexEventType.notification` whenever a notification is received to flutter application, and `ReflexEventType.reply` whenever an automated reply is sent.
211+
212+
* **packageName**: Application's package name from which notifications are received and reply are sent.
213+
214+
* **title**: Notification title
215+
216+
* **message**: Message contained in the notification and while sending reply.
217+
218+
* **timestamp**: Timestamp of the notification received and reply sent.
219+
220+
### Listen notification from specific apps
221+
222+
Specify list of package names to listen to notifications from those applications.
223+
224+
If `packageNameList: null` plugin will listen to notifications from all packages.
225+
226+
```dart
227+
Reflex reflex = Reflex(
228+
debug: true,
229+
packageNameList: ["com.whatsapp", "com.facebook"],
230+
);
231+
```
232+
233+
### Avoid notification from specific apps
234+
235+
Specify package name exception list to avoid listening notifications from those applications.
236+
237+
If `packageNameExceptionList: null`, the plugin will listen to notifications for `packageNameList` if not null.
238+
239+
```dart
240+
Reflex reflex = Reflex(
241+
debug: true,
242+
packageNameExceptionList: ["com.whatsapp"],
243+
);
244+
```
245+
246+
### Auto Reply
247+
248+
Send an automated reply while listening notification.
249+
250+
```dart
251+
AutoReply autoReply = AutoReply(
252+
message: "[Reflex] This is an automated reply.",
253+
),
254+
```
255+
256+
#### Auto reply specific apps
257+
258+
Specify `packageNameList` in AutoReply to reply to specific applications.
259+
260+
```dart
261+
AutoReply autoReply = AutoReply(
262+
packageNameList: ["com.whatsapp"],
263+
message: "[Reflex] This is an automated reply.",
264+
),
265+
```
266+
267+
The `AutoReply` object is used by the Reflex's `autoReply` field to automatically reply to applications.
268+
269+
```dart
270+
Reflex reflex = Reflex(
271+
debug: true,
272+
packageNameList: ["com.whatsapp", "com.tyup"],
273+
packageNameExceptionList: ["com.miui.securitycenter"],
274+
autoReply: AutoReply(
275+
packageNameList: ["com.whatsapp"],
276+
message: "[Reflex] This is an automated reply.",
277+
),
278+
);
279+
```
280+
281+
If the `autoReply` field is `null` in `Reflex` class, Auto reply feature will be disabled.
282+
283+
## Ambiguity
284+
285+
A `ReflexException` will be thrown if,
286+
287+
* `Reflex`'s `packageNameList` and `packageNameExceptionList` contains any similar package name.
288+
289+
* any package name in `AutoReply`'s `packageNameList` is contained in `Reflex`'s `packageNameExceptionList`.
65290

66291
## Project Created & Maintained By
67292

Diff for: android/.idea/gradle.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: android/.idea/runConfigurations.xml

-10
This file was deleted.

Diff for: android/build.gradle

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
}
99

1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:4.1.0'
11+
classpath 'com.android.tools.build:gradle:4.2.2'
1212
}
1313
}
1414

@@ -22,7 +22,7 @@ rootProject.allprojects {
2222
apply plugin: 'com.android.library'
2323

2424
android {
25-
compileSdkVersion 30
25+
compileSdkVersion 31
2626

2727
compileOptions {
2828
sourceCompatibility JavaVersion.VERSION_1_8
@@ -37,3 +37,7 @@ android {
3737
dependencies {
3838
implementation 'org.jetbrains:annotations:15.0'
3939
}
40+
41+
repositories {
42+
mavenCentral()
43+
}

0 commit comments

Comments
 (0)