android - 如何显示从数据库检索内容的通知?

标签 android

我正在 Android 中制作一个笔记应用程序,它有一个标题和一个正文,用户可以将其保存到 SQLite 数据库中。还有一个选项可以保存带有提醒的注释。

如何显示通知,例如,通知标题作为数据库中的注释标题,通知正文作为数据库中的正文?

我的数据库有每个笔记的属性 id、text、body。

如何在用户单击通知时显示正确的 ID? 如何仅打开特定笔记?

最佳答案

看看这个

这可以帮助您显示简单的通知

public class StatusBar extends Activity implements OnClickListener{

NotificationManager nm;
static final int uniqueID = 1394885;


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.statusbar);
    Button stat = (Button)findViewById(R.id.bStatusBar);
    stat.setOnClickListener(this);
    nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.cancel(uniqueID);
}

public void onClick(View v) {
    // TODO Auto-generated method stub
    Intent intent = new Intent(this, StatusBar.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
    String body = "This is a message from Travis, thanks for your support";
    String title = "Travis C.";
    Notification n = new Notification(R.drawable.lightning, body, System.currentTimeMillis());
    n.setLatestEventInfo(this, title, body, pi);
    n.defaults = Notification.DEFAULT_ALL;
    nm.notify(uniqueID, n);
    finish();
}

}

关于android - 如何显示从数据库检索内容的通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25249187/

相关文章:

android - 获取Android通知面板宽度

Android:谷歌文档发送 Intent ?

android - 如何实现GeckoView?

java - 错误描述 : Cannot return to provided redirect_uri

java - Android ServerSocket 端口选择

javascript - 如何从 Activity 中将字符串值传递给 webView

android - 从临时文件加载 Base 64 图像问题

android - 将新项目添加到 Android 上的 ListView 顶部?

android - LibGDX:当我更换屏幕时,我的特定类如何继续保留?

android - 我们在 android 中有鼠标悬停事件吗?