-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Implement Firebase Cloud Messaging & In-app Messaging #296
Conversation
👀 |
// .addOnSuccessListener(new OnSuccessListener<String>() { | ||
// @Override | ||
// public void onSuccess(String s) { | ||
// Timber.d("timber: fcm getToken= %s", s); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to log fcm token, in case we need to test fcm with specific device
if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree()); | ||
DISPLAY_HEIGHT_PX = Resources.getSystem().getDisplayMetrics().heightPixels; | ||
|
||
String afID = Utils.fetchPartnerKey(this, PartnerNames.AFDEVID); | ||
AppsFlyerLib.getInstance().init(afID, null, this); | ||
AppsFlyerLib.getInstance().start(this); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, this is I am using the shortcut/menu that mentioned before
private final ActivityResultLauncher<String> requestNotificationPermissionLauncher = | ||
registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { | ||
if (isGranted) { | ||
Toast.makeText(app, R.string.permission_notification_granted, Toast.LENGTH_SHORT).show(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if granted just show toast here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG
showInAppReviewDialogIfNeeded(); | ||
} | ||
|
||
private void setupNotificationPermission() { | ||
//https://developer.android.com/develop/ui/views/notifications/notification-permission |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
notification runtime permission available from API level 33 and higher
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.POST_NOTIFICATIONS)) { | ||
new AlertDialog.Builder(this) | ||
.setTitle(R.string.permission_info) | ||
.setMessage(R.string.please_grant_notification_permission) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just show dialog if shouldShowRequestPermissionRationale
return true
@@ -141,6 +141,7 @@ private BRConstants() { | |||
public static final String _20240101_US = "user_signup"; | |||
public static final String _20241006_DRR = "did_request_rating"; | |||
public static final String _20241006_UCR = "user_completed_rating"; | |||
public static final String _HOME_OPEN = "home_open"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is event to trigger display in-app messaging, will share the video on slack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
|
||
val channelId = remoteMessage.notification?.channelId ?: NOTIFICATION_CHANNEL_ID_GENERAL | ||
val title = remoteMessage.data["title"] ?: return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regarding notification vs data payload details here https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages
@@ -776,4 +776,13 @@ | |||
<string name="Announce.no_thanks">No, thanks!</string> | |||
<string name="Fees.Service">Service</string> | |||
<string name="ConfirmationAllFees.Label">Fees:</string> | |||
|
|||
<string name="notification_channel_name_general" translatable="false">General</string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently I just create this new copy, do we have to translate into all of languages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. What do you think @kcw-grunt ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for channel name maybe no need to translate, but like please_grant_notification_permission
I think we need to translate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. Im wrapping my head around leveraging the Google Translate in the FCM dashboard @andhikayuana
mockkStatic(NotificationManagerCompat::class) | ||
every { NotificationManagerCompat.from(context).notify(any()) } just Runs | ||
|
||
//todo: revisit, test still fail because specific platform API e.g. android.app.Notification$Builder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to revisit later, since error with specific API platform here
.setContentIntent(pendingIntent) | ||
.setAutoCancel(true) | ||
|
||
NotificationManagerCompat.from(context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does NotificationManagerCompat do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to post/cancel android notification on the status bar android
more https://developer.android.com/develop/ui/views/notifications/build-notification#notify
) == PackageManager.PERMISSION_GRANTED | ||
} | ||
|
||
@JvmStatic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this ask user the permission for notifications when user open the app for the first time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is for general purpose runtime permission, you can find the implementation at BreadActivity
https://github.com/litecoin-foundation/litewallet-android/pull/296/files#diff-63c75cf9310b8ced1dd7141be03a32c7b4071d12c12e1876074beaf0035eeb0dR152
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@josikie this allows us to reach the users that are using the app. So, we dont need push notification authorization
@andhikayuana please correct me if I got this wrong...;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, noted! @kcw-grunt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you! @andhikayuana
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
But, everyone in the Litewallet team needs to test this feature and we need to ilicit feedback as we do iOS version
) == PackageManager.PERMISSION_GRANTED | ||
} | ||
|
||
@JvmStatic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@josikie this allows us to reach the users that are using the app. So, we dont need push notification authorization
@andhikayuana please correct me if I got this wrong...;)
object PermissionUtil { | ||
|
||
@JvmStatic | ||
fun hasPermissions(context: Context, permissions: Array<String>): Boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andhikayuana is this for inapp only permission? Or is this for auth for when the app is closed. Or is it both?
private final ActivityResultLauncher<String> requestNotificationPermissionLauncher = | ||
registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { | ||
if (isGranted) { | ||
Toast.makeText(app, R.string.permission_notification_granted, Toast.LENGTH_SHORT).show(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG
@@ -776,4 +776,13 @@ | |||
<string name="Announce.no_thanks">No, thanks!</string> | |||
<string name="Fees.Service">Service</string> | |||
<string name="ConfirmationAllFees.Label">Fees:</string> | |||
|
|||
<string name="notification_channel_name_general" translatable="false">General</string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. Im wrapping my head around leveraging the Google Translate in the FCM dashboard @andhikayuana
* feat: add notification channel * feat: add PermissionUtil * feat: request notification permission for API 33 or above * feat: implement firebase in-app messaging * feat: implement simple cloud messaging * feat: add NotificationHandlerTest
Overview
Simple implementation for Firebase Cloud Messaging and Firebase In-app Messaging
Issue
https://github.com/litecoin-foundation/litewallet-engineering/issues/3
Self Test
will share on slack