Android: adding text from textView to status bar

Is it possible to add a line taken from textView to the status bar. I want to constantly display text dynamically updated as a text view from the main activity of applications.

TextView message = (TextView) findViewById(R.id.textView1);
message.setText("This I want to add to status bar");
+2
source share
3 answers

Yes, you can

private static void generateNotification(Context context, String message) {
        int icon = R.drawable.ic_status;
        long when = System.currentTimeMillis();
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(icon, message, when);
        String title = context.getString(R.string.app_name); // Here you can pass the value of your TextView
        Intent notificationIntent = new Intent(context, SplashScreen.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent = PendingIntent.getActivity(context, 0,
                notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, notification);
    }
+2
source

TextView message = (TextView) findViewById (R.id.textView1); message.setText ("This I want to add to the status bar");

ActionBar actionBar = getSupportActionBar (); actionBar.setTittle (message.getText () ToString ().);

This should solve your problem.

+1
source

Yes, you can show the text from the text view to the status bar, you need to create a notification And here is a guide on how to update the notification text at run time.

0
source

All Articles