Skip to content Skip to sidebar Skip to footer

How To Change App Name In Notification Bar Programmatically

I want to change app name in the notification bar but I cannot find it simple solution. They say have to change app name. And I find this lib. https://github.com/myinnos/AppIconNam

Solution 1:

you need to use setContentTitle to change the title.

Solution 2:

publicclassMyFirebaseMessagingServiceextendsFirebaseMessagingService {

    privatestaticfinalStringTAG= MyFirebaseMessagingService.class.getSimpleName();

    private NotificationUtils notificationUtils;

    @OverridepublicvoidonMessageReceived(RemoteMessage remoteMessage) {
        Log.d("Push.....", "From: " + remoteMessage.getFrom());

        if (remoteMessage == null)
            return;

        // Check if message contains a notification payload.if (remoteMessage.getNotification() != null) {
            Log.e(TAG, "Notification Body: " + remoteMessage.getNotification().getBody());
            handleNotification(remoteMessage.getNotification().getBody());
        }

        // Check if message contains a data payload.if (remoteMessage.getData().size() > 0) {
            Log.e(TAG, "Data Payload: " + remoteMessage.getData().toString());

            try {
                JSONObjectjson=newJSONObject(remoteMessage.getData().toString());
                handleDataMessage(json);
            } catch (Exception e) {
                Log.e(TAG, "Exception: " + e.getMessage());
            }
        }
    }

    privatevoidhandleNotification(String message) {
        if (!NotificationUtils.isAppIsInBackground(getApplicationContext())) {
            // app is in foreground, broadcast the push messageIntentpushNotification=newIntent(Config.PUSH_NOTIFICATION);
            pushNotification.putExtra("message", message);
            LocalBroadcastManager.getInstance(this).sendBroadcast(pushNotification);

            // play notification soundNotificationUtilsnotificationUtils=newNotificationUtils(getApplicationContext());
            notificationUtils.playNotificationSound();
        }else{
            // If the app is in background, firebase itself handles the notification
        }
    }

    privatevoidhandleDataMessage(JSONObject json) {
        Log.e(TAG, "push json: " + json.toString());

        try {
            JSONObjectdata= json.getJSONObject("data");
            Stringtitle= data.getString("title");
            Stringmessage= data.getString("message");
            booleanisBackground= data.getBoolean("is_background");
            StringimageUrl= data.getString("image");
            Stringtimestamp= data.getString("timestamp");
            JSONObjectpayload= data.getJSONObject("payload");
            Log.e(TAG, "title: " + title);
            Log.e(TAG, "message: " + message);
            Log.e(TAG, "isBackground: " + isBackground);
            Log.e(TAG, "payload: " + payload.toString());
            Log.e(TAG, "imageUrl: " + imageUrl);
            Log.e(TAG, "timestamp: " + timestamp);


            if (!NotificationUtils.isAppIsInBackground(getApplicationContext())) {
                // app is in foreground, broadcast the push messageIntentpushNotification=newIntent(Config.PUSH_NOTIFICATION);
                pushNotification.putExtra("message", message);
                LocalBroadcastManager.getInstance(this).sendBroadcast(pushNotification);

                // play notification soundNotificationUtilsnotificationUtils=newNotificationUtils(getApplicationContext());
                notificationUtils.playNotificationSound();
            } else {
                // app is in background, show the notification in notification trayIntentresultIntent=newIntent(getApplicationContext(), ChatActivity.class);
                resultIntent.putExtra("message", message);

                // check for image attachmentif (TextUtils.isEmpty(imageUrl)) {
                    showNotificationMessage(getApplicationContext(), title, message, timestamp, resultIntent);
                } else {
                    // image is present, show notification with image
                    showNotificationMessageWithBigImage(getApplicationContext(), title, message, timestamp, resultIntent, imageUrl);
                }
            }
        } catch (JSONException e) {
            Log.e(TAG, "Json Exception: " + e.getMessage());
        } catch (Exception e) {
            Log.e(TAG, "Exception: " + e.getMessage());
        }
    }

    /**
     * Showing notification with text only
     */privatevoidshowNotificationMessage(Context context, String title, String message, String timeStamp, Intent intent) {
        notificationUtils = newNotificationUtils(context);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        notificationUtils.showNotificationMessage(title, message, timeStamp, intent);
    }

    /**
     * Showing notification with text and image
     */privatevoidshowNotificationMessageWithBigImage(Context context, String title, String message, String timeStamp, Intent intent, String imageUrl) {
        notificationUtils = newNotificationUtils(context);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        notificationUtils.showNotificationMessage(title, message, timeStamp, intent, imageUrl);
    }
}

Solution 3:

Try this:

Notificationnoti=newNotification.Builder(mContext)
         .setContentTitle("Your title")
         .setContentText(subject)
         .setSmallIcon(R.drawable.new_mail)
         .setLargeIcon(aBitmap)
         .build();

Already have this on Notification.Builder.

Post a Comment for "How To Change App Name In Notification Bar Programmatically"