本文介绍了Android:将文本从 textView 添加到状态栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以将从 textView 获取的字符串添加到状态栏.我想不断地显示文本,从应用程序的主要活动中动态更新为 textView.
Is it possible to add the String taken from textView to Status Bar. I want to show text constantly , dynamically updated as textView from apps main activity.
TextView message = (TextView) findViewById(R.id.textView1);
message.setText("This I want to add to status bar");
推荐答案
可以的
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);
}
这篇关于Android:将文本从 textView 添加到状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!