I want to handle multi notification using the columns of SQLite database. How can I input the array String into notification builder? If not using array, what should I do as I want? Please help!
I have declared the 3 array with these:
ArrayList<String> reminder1 = new ArrayList<String>();
ArrayList <Long> totalMill1 = new ArrayList<Long>();
ArrayList <String> key1 = new ArrayList<String>();
The code of Notification part:
private void sendNotification(String notiText, Intent intent,String text, int intID){ // I want to put reminder1 instead of notiText and key1 instead of intID
/*get notification service*/
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
/*set the activity when click*/
Intent dismissIntent = new Intent(this, CreateRecord.class);
Notification.Builder builder =
new Notification.Builder(this)
.setSmallIcon(R.drawable.notification)
.setContentTitle("Remainder")
.setContentText(notiText)
.setContentInfo(text)
.setStyle(new Notification.BigTextStyle()
.bigText(notiText))
.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(), 0))
.setAutoCancel(true);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this).addParentStack(CreateRecord.class).addNextIntent(intent);
PendingIntent.getActivity(this, 0, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT);
manager.notify(intID, builder.build());
Log.i("Mess", "success");
}
And this is the cursor:
private void cursor(){
Cursor cursor = null;
String query = "SELECT * FROM " + databaseHelper.TABLE_NAME;
cursor = dataBase.rawQuery(query,null);
reminder1.clear();
totalMill1.clear();
key1.clear();
if (cursor != null && cursor.getCount() > 0){
while(cursor.moveToNext()) {
String strID = cursor.getString(cursor.getColumnIndex(databaseHelper.KEY_ID));
String strMessage = cursor.getString(cursor.getColumnIndex(databaseHelper.KEY_Remind));
Integer strReceive = cursor.getInt(cursor.getColumnIndex(databaseHelper.KEY_Receive));
String strToUser = cursor.getString(cursor.getColumnIndex(databaseHelper.KEY_ToUser));
Long x = new Long(strReceive);
Date cursorDate = new Date(((long)strReceive)*1000L);
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm");
String mainDate = dateFormat.format(cursorDate);
notiID = strID; //attribute I want to put into notification , but this can only show last column
notiText = strMessage; //same
notiDate = ((long)strReceive)*1000L; //same
reminder1.add(strMessage); //<---all column in my db, but i fail to add into notification builder
totalMill1.add(x); //same
key1.add(strID); //same
}
}else {
Log.e("error", "check if cursor is null");
}
if (cursor != null && !cursor.isClosed())
cursor.close();
}
Aucun commentaire:
Enregistrer un commentaire