Gem
Gem

Reputation: 1606

Show ticker text without a notification

I have a requirement i my project. We want to show a text in the status bar where we have time and network signal icons. But we don't want to have notification. the text just display, scroll as usual and then disappear completely. There should be no notification in the panel. Any idea how to achieve this? I know there is no straightforward way to do this. Can any one provide any hack ??

Update:

I am able to generate notification and cancel it after some time. For this i have created a handler and cancel it after some time. But the problem is now to calculate time based on text size. I want to cancel the notification only when it completely rolled out.

final NotificationManager mNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                context)
                .setSmallIcon(R.drawable.icon)
                .setTicker("abcd efgh ijkl mnop qrst uvwx yz abcd efgh ijkl mnop qrst uvwx yz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz")

                .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
                .setOnlyAlertOnce(true);




        mNotificationManager.notify(SharedPreferenceUtil.getInstance()
                .getNotificationId(context), mBuilder.build());

        Handler handler = new Handler();

        handler.postDelayed(new Runnable() {

            @Override
            public void run() {
                Utility.Log("Notification Removed", Log.VERBOSE);
                mNotificationManager.cancel(id);
            }
        }, 10000);

        Utility.Log("Notification Posted", Log.VERBOSE);

Upvotes: 2

Views: 1878

Answers (2)

Biraj Zalavadia
Biraj Zalavadia

Reputation: 28484

Yes, you can do it

You set the notification like this:

notificationManager.notify(0, notification);

And After that you can remove from the notification list like this

NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationmanager.cancel(0);

Upvotes: 2

Drake29a
Drake29a

Reputation: 896

Have you tried posting notification, and instantly dismissing it?

Upvotes: 1

Related Questions