rajathans
rajathans

Reputation: 197

How to display notification with content retrieved from a database?

I'm making a note taking app in Android, which has a title and a body that the user can save to a SQLite database. There is also an option to save the note with a reminder.

How can I display a notification with say, the title of a notification as the note title from the database, and body of the notification as the body from database?

My database has attributes id,text,body for every note.

How can I display the correct ID and when the user clicks on the notification? How do I open the specific note only?

Upvotes: 2

Views: 524

Answers (1)

Amer Hadi
Amer Hadi

Reputation: 277

check this out

that's help you to display a simple notification

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();
}

}

Upvotes: 2

Related Questions