-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
crow
committed
Oct 19, 2024
1 parent
8fa3a69
commit ac2cd52
Showing
19 changed files
with
1,083 additions
and
90 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
16 changes: 16 additions & 0 deletions
16
android/src/main/kotlin/com/airship/flutter/AirshipPluginExtender.kt
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,16 @@ | ||
/* Copyright Urban Airship and Contributors */ | ||
|
||
package com.urbanairship.reactnative | ||
|
||
import android.content.Context | ||
import com.urbanairship.UAirship | ||
|
||
/** | ||
* Extender that will be called during takeOff to customize the airship instance. | ||
* Register the extender fully qualified class name in the manifest under the key | ||
* `com.urbanairship.flutter.AIRSHIP_EXTENDER`. | ||
*/ | ||
@Deprecated("Use com.urbanairship.android.framework.proxy.AirshipPluginExtender instead and register it under the manifest key `com.urbanairship.plugin.extender`") | ||
interface AirshipExtender { | ||
fun onAirshipReady(context: Context, airship: UAirship) | ||
} |
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
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,69 @@ | ||
package com.urbanairship.sample | ||
|
||
import android.app.NotificationChannel | ||
import android.app.NotificationManager | ||
import android.app.PendingIntent | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Build | ||
import androidx.annotation.Keep | ||
import androidx.core.app.NotificationCompat | ||
import androidx.core.app.NotificationManagerCompat | ||
import com.urbanairship.UAirship | ||
import com.urbanairship.android.framework.proxy.AirshipPluginExtender | ||
import com.urbanairship.json.requireField | ||
import com.urbanairship.liveupdate.LiveUpdate | ||
import com.urbanairship.liveupdate.LiveUpdateEvent | ||
import com.urbanairship.liveupdate.LiveUpdateManager | ||
import com.urbanairship.liveupdate.LiveUpdateResult | ||
import com.urbanairship.liveupdate.SuspendLiveUpdateNotificationHandler | ||
|
||
|
||
@Keep | ||
public final class AirshipExtender: AirshipPluginExtender { | ||
override fun onAirshipReady(context: Context, airship: UAirship) { | ||
LiveUpdateManager.shared().register("Example", ExampleLiveUpdateHandler()) | ||
} | ||
} | ||
|
||
public final class ExampleLiveUpdateHandler: SuspendLiveUpdateNotificationHandler() { | ||
override suspend fun onUpdate( | ||
context: Context, | ||
event: LiveUpdateEvent, | ||
update: LiveUpdate | ||
): LiveUpdateResult<NotificationCompat.Builder> { | ||
|
||
if (event == LiveUpdateEvent.END) { | ||
// Dismiss the live update on END. The default behavior will leave the Live Update | ||
// in the notification tray until the dismissal time is reached or the user dismisses it. | ||
return LiveUpdateResult.cancel() | ||
} | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
val importance = NotificationManager.IMPORTANCE_DEFAULT | ||
val channel = NotificationChannel("emoji-example", "Emoji example", importance) | ||
channel.description = "Emoji example" | ||
NotificationManagerCompat.from(context).createNotificationChannel(channel) | ||
} | ||
|
||
val launchIntent = context.packageManager | ||
.getLaunchIntentForPackage(context.packageName) | ||
?.addCategory(update.name) | ||
?.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP) | ||
?.setPackage(null) | ||
|
||
val contentIntent = PendingIntent.getActivity( | ||
context, 0, launchIntent, PendingIntent.FLAG_IMMUTABLE | ||
) | ||
|
||
val notification = NotificationCompat.Builder(context, "emoji-example") | ||
.setSmallIcon(R.drawable.ic_notification) | ||
.setPriority(NotificationCompat.PRIORITY_MAX) | ||
.setCategory(NotificationCompat.CATEGORY_EVENT) | ||
.setContentTitle("Example Live Update") | ||
.setContentText(update.content.requireField<String>("emoji")) | ||
.setContentIntent(contentIntent) | ||
|
||
return LiveUpdateResult.ok(notification) | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
example/android/app/src/main/res/drawable/ic_notification.xml
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</selector> |
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
Oops, something went wrong.