use resources for notification text for localization

Signed-off-by: yenda <eric@status.im>
This commit is contained in:
yenda 2020-06-15 17:12:11 +02:00
parent 9abf9d3891
commit ddcb1fa54a
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
3 changed files with 15 additions and 6 deletions

View File

@ -33,7 +33,7 @@ public class ForegroundService extends Service {
NotificationManager notificationManager = NotificationManager notificationManager =
context.getSystemService(NotificationManager.class); context.getSystemService(NotificationManager.class);
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
"Status Service", context.getResources().getString(R.string.status_service),
NotificationManager.IMPORTANCE_HIGH); NotificationManager.IMPORTANCE_HIGH);
channel.setShowBadge(false); channel.setShowBadge(false);
notificationManager.createNotificationChannel(channel); notificationManager.createNotificationChannel(channel);
@ -57,16 +57,18 @@ public class ForegroundService extends Service {
Intent stopIntent = new Intent(NewMessageSignalHandler.ACTION_TAP_STOP); Intent stopIntent = new Intent(NewMessageSignalHandler.ACTION_TAP_STOP);
PendingIntent stopPendingIntent = PendingIntent.getBroadcast(context, 0, stopIntent, PendingIntent.FLAG_CANCEL_CURRENT); PendingIntent stopPendingIntent = PendingIntent.getBroadcast(context, 0, stopIntent, PendingIntent.FLAG_CANCEL_CURRENT);
String content = "Keep Status running to receive notifications"; String content = context.getResources().getString(R.string.keep_status_running);
Notification notification = new NotificationCompat.Builder(context, CHANNEL_ID) Notification notification = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_stat_notify_status) .setSmallIcon(R.drawable.ic_stat_notify_status)
.setContentTitle("Background notification service opened") .setContentTitle(context.getResources().getString(R.string.background_service_opened))
.setContentText(content) .setContentText(content)
.setPriority(NotificationCompat.PRIORITY_HIGH) .setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_MESSAGE) .setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setContentIntent(pendingIntent) .setContentIntent(pendingIntent)
.setNumber(0) .setNumber(0)
.addAction(R.drawable.ic_stat_notify_status, "STOP", stopPendingIntent) .addAction(R.drawable.ic_stat_notify_status,
context.getResources().getString(R.string.stop),
stopPendingIntent)
.build(); .build();
// the id of the foreground notification MUST NOT be 0 // the id of the foreground notification MUST NOT be 0
startForeground(1, notification); startForeground(1, notification);

View File

@ -49,7 +49,6 @@ public class NewMessageSignalHandler {
public static final String ACTION_TAP_STOP = "im.status.ethereum.module.TAP_STOP"; public static final String ACTION_TAP_STOP = "im.status.ethereum.module.TAP_STOP";
private static final String GROUP_STATUS_MESSAGES = "im.status.notifications.message"; private static final String GROUP_STATUS_MESSAGES = "im.status.notifications.message";
private static final String CHANNEL_NAME = "Status"; private static final String CHANNEL_NAME = "Status";
private static final String CHANNEL_DESCRIPTION = "Get notifications on new messages and mentions";
private static final String CHANNEL_ID = "status-chat-notifications"; private static final String CHANNEL_ID = "status-chat-notifications";
private static final String TAG = "StatusModule"; private static final String TAG = "StatusModule";
private NotificationManager notificationManager; private NotificationManager notificationManager;
@ -161,7 +160,7 @@ public class NewMessageSignalHandler {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Uri soundUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() + "/" + R.raw.notification_sound); Uri soundUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() + "/" + R.raw.notification_sound);
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH); NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
channel.setDescription(CHANNEL_DESCRIPTION); channel.setDescription(context.getResources().getString(R.string.channel_description));
AudioAttributes audioAttributes = new AudioAttributes.Builder() AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION) .setUsage(AudioAttributes.USAGE_NOTIFICATION)
.build(); .build();

View File

@ -0,0 +1,8 @@
<resources>
<string name="status_service">Status Service</string>
<string name="stop">STOP</string>
<string name="keep_status_running">Keep Status running to receive notifications</string>
<string name="background_service_opened">Background notification service opened</string>
<string name="channel_description">Get notifications on new messages and mentions</string>
</resources>