android - 如何在 Android 状态栏通知上设置文本

标签 android

我不知道如何在android中设置状态栏通知请给出一些想法

最佳答案

@spectrum 你会引用:http://developer.android.com/guide/topics/ui/notifiers/notifications.html

通知

Notification notification = new Notification(
    android.R.drawable.stat_sys_warning,  //Icon to use
    "Hello World!", //Text
    System.currentTimeMillis() //When to display - i.e. now
);

创建一个 PendingIntent 以在用户点击通知时执行某些操作

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.stackoverflow.com"));
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);

//Add to the Notification
notification.setLatestEventInfo(
    getApplicationContext(),
    "Stack Overflow", //Title of detail view
    "This will launch Stack Overflow",  //Text on detail view
    pi
);
//Display the Notification
NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(ID_HELLO_WORLD, notification);  //ID_HELLO_WORLD is a int ID

关于android - 如何在 Android 状态栏通知上设置文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5840166/

相关文章:

android - 以编程方式按下另一个应用程序 Activity 中的按钮

android - 如何录制并保存为 mp3 在线流媒体音频

带有relativelayout的android webview和进度条

java - 在 Android 中解析一些 HTML 代码的最佳方法

android - 无法使用 Google Drive Android API 创建电子表格文件

java - 如何从此对象中访问 deviceName 和 deviceHardwareAddress?

java - 开始使用 google Place Autocomplete API 调用

android - 如何在android 2.2中播放shoutcast流

java - 实现 Android 手势识别工具框架,在生成的构建文件中接收错误

Android OpenCV getPerspectiveTransform 和 warpPerspective