forked from MaikuB/flutter_local_notifications
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '4b723e750d1371206520b10a122a444c4bba7475' into mindapps…
…_flutter_local_notifications * commit '4b723e750d1371206520b10a122a444c4bba7475': (76 commits) [flutter_local_notifications] update docs on initialize method to describe callbacks more (MaikuB#1841) enable usePubspecOverrides with melos (MaikuB#1822) replaced placeholder.com with dummyimage.com in example app due to Cloudflare blocking requests (MaikuB#1821) Google Java Format [flutter_local_notifications] Fixes MaikuB#1486 :Adds ability to count down chronometer with chronometerCountDown (MaikuB#1778) Implement options to hide or crop attachments in the thumbnail on iOS (MaikuB#1785) bump linux plugin's Flutter version requirement to 3.0.0 and add explicit ffi dependency (MaikuB#1812) [flutter_local_notifications] re-add imports needed for Flutter 3.0 and add build tasks that use Flutter 3.0 (MaikuB#1811) updated example app to not request the ability to display critical alerts (MaikuB#1809) Add note about keeping `@mipmap/ic_launcher` resource (MaikuB#1804) Recommend WindowManager to fix Android 12L+ bugs (MaikuB#1803) [flutter_local_notifications] Upgraded Android Gradle Plugin to fix Android build (MaikuB#1781) [flutter_local_notifications] fixes parsing of callback handles for notification actions on Android (MaikuB#1798) [flutter_local_notifications] fix Kotlin version used in example app (MaikuB#1791) Updates readme for iOS Setup (MaikuB#1776) added missing kudos for contributions relating to flutter_local_notifications 12.0.3 release release flutter_local_notifications 12.0.3 updated code snippet in readme on requesting permissions on Android (MaikuB#1754) Google Java Format Drop registerWith in Android plugin (MaikuB#1745) ...
- Loading branch information
Showing
109 changed files
with
6,743 additions
and
2,116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "pub" | ||
directory: "/flutter_local_notifications_platform_interface" | ||
schedule: | ||
interval: "daily" | ||
- package-ecosystem: "pub" | ||
directory: "/flutter_local_notifications_linux" | ||
schedule: | ||
interval: "daily" | ||
- package-ecosystem: "pub" | ||
directory: "/flutter_local_notifications" | ||
schedule: | ||
interval: "daily" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
pubspec.lock | ||
.vscode | ||
*.idea | ||
*.DS_Store | ||
*.DS_Store | ||
|
||
# Melos | ||
pubspec_overrides.yaml |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
...ndroid/src/main/java/com/dexterous/flutterlocalnotifications/ActionBroadcastReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package com.dexterous.flutterlocalnotifications; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.util.Log; | ||
|
||
import androidx.annotation.Keep; | ||
import androidx.annotation.Nullable; | ||
import androidx.annotation.VisibleForTesting; | ||
import androidx.core.app.NotificationManagerCompat; | ||
|
||
import com.dexterous.flutterlocalnotifications.isolate.IsolatePreferences; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import io.flutter.FlutterInjector; | ||
import io.flutter.embedding.engine.FlutterEngine; | ||
import io.flutter.embedding.engine.dart.DartExecutor; | ||
import io.flutter.embedding.engine.loader.FlutterLoader; | ||
import io.flutter.plugin.common.EventChannel; | ||
import io.flutter.plugin.common.EventChannel.EventSink; | ||
import io.flutter.plugin.common.EventChannel.StreamHandler; | ||
import io.flutter.view.FlutterCallbackInformation; | ||
|
||
public class ActionBroadcastReceiver extends BroadcastReceiver { | ||
public static final String ACTION_TAPPED = | ||
"com.dexterous.flutterlocalnotifications.ActionBroadcastReceiver.ACTION_TAPPED"; | ||
private static final String TAG = "ActionBroadcastReceiver"; | ||
@Nullable private static ActionEventSink actionEventSink; | ||
@Nullable private static FlutterEngine engine; | ||
IsolatePreferences preferences; | ||
|
||
@VisibleForTesting | ||
ActionBroadcastReceiver(IsolatePreferences preferences) { | ||
this.preferences = preferences; | ||
} | ||
|
||
@Keep | ||
public ActionBroadcastReceiver() {} | ||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
if (!ACTION_TAPPED.equalsIgnoreCase(intent.getAction())) { | ||
return; | ||
} | ||
|
||
preferences = preferences == null ? new IsolatePreferences(context) : preferences; | ||
|
||
final Map<String, Object> action = | ||
FlutterLocalNotificationsPlugin.extractNotificationResponseMap(intent); | ||
|
||
if (intent.getBooleanExtra(FlutterLocalNotificationsPlugin.CANCEL_NOTIFICATION, false)) { | ||
NotificationManagerCompat.from(context) | ||
.cancel((int) action.get(FlutterLocalNotificationsPlugin.NOTIFICATION_ID)); | ||
} | ||
|
||
if (actionEventSink == null) { | ||
actionEventSink = new ActionEventSink(); | ||
} | ||
actionEventSink.addItem(action); | ||
|
||
startEngine(context); | ||
} | ||
|
||
private void startEngine(Context context) { | ||
if (engine != null) { | ||
Log.e(TAG, "Engine is already initialised"); | ||
return; | ||
} | ||
|
||
FlutterInjector injector = FlutterInjector.instance(); | ||
FlutterLoader loader = injector.flutterLoader(); | ||
|
||
loader.startInitialization(context); | ||
loader.ensureInitializationComplete(context, null); | ||
|
||
engine = new FlutterEngine(context); | ||
|
||
/// This lookup needs to be done after creating an instance of `FlutterEngine` or lookup may | ||
// fail | ||
FlutterCallbackInformation dispatcherHandle = preferences.lookupDispatcherHandle(); | ||
if (dispatcherHandle == null) { | ||
Log.w(TAG, "Callback information could not be retrieved"); | ||
return; | ||
} | ||
|
||
DartExecutor dartExecutor = engine.getDartExecutor(); | ||
|
||
initializeEventChannel(dartExecutor); | ||
|
||
String dartBundlePath = loader.findAppBundlePath(); | ||
dartExecutor.executeDartCallback( | ||
new DartExecutor.DartCallback(context.getAssets(), dartBundlePath, dispatcherHandle)); | ||
} | ||
|
||
private void initializeEventChannel(DartExecutor dartExecutor) { | ||
EventChannel channel = | ||
new EventChannel( | ||
dartExecutor.getBinaryMessenger(), "dexterous.com/flutter/local_notifications/actions"); | ||
channel.setStreamHandler(actionEventSink); | ||
} | ||
|
||
private static class ActionEventSink implements StreamHandler { | ||
|
||
final List<Map<String, Object>> cache = new ArrayList<>(); | ||
|
||
@Nullable private EventSink eventSink; | ||
|
||
public void addItem(Map<String, Object> item) { | ||
if (eventSink != null) { | ||
eventSink.success(item); | ||
} else { | ||
cache.add(item); | ||
} | ||
} | ||
|
||
@Override | ||
public void onListen(Object arguments, EventSink events) { | ||
for (Map<String, Object> item : cache) { | ||
events.success(item); | ||
} | ||
|
||
cache.clear(); | ||
eventSink = events; | ||
} | ||
|
||
@Override | ||
public void onCancel(Object arguments) { | ||
eventSink = null; | ||
} | ||
} | ||
} |
Oops, something went wrong.