In my application I have a LocationTester Service implements LocationListener
which is responsible for retrieving the Reminders from sqlite Db and comparing their distances with current location in onLocationChanged()
method and then present the information if the distance is less than 1km and then throw notification related to that particular reminder.
The problem is that when I check for a certain location with a successful response every thing goes well even the toast is displaying where it meets the condition but I am not getting any sort of notification.
LocationTester Service:
public void onLocationChanged(Location location) {
dataSrc.open();
ArrayList<Reminders> rems = (ArrayList<Reminders>) dataSrc.findALL();
for(Reminders x:rems){
Location locs = new Location("");
locs.setLatitude(x.getLat());
locs.setLongitude(x.getLng());
double dis = location.distanceTo(locs);
if(dis<=1000){
String title = x.getTitle();
String des = x.getDescription();
Intent intent = new Intent(this,ActivityShowReminders.class);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle(title);
builder.setContentText(des);
noteManag = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
noteManag.notify(noteId,builder.build());
noteId += 1;
Toast.makeText(this, title+"("+des+")", Toast.LENGTH_LONG).show();
}
}
datasrc:
public List<Reminders> findALL(){
List<Reminders> reminder = new ArrayList<Reminders>();
Cursor cursor = database.query(ReminderDBOpenHelper.TABLE_REMINDER, allColumns,
null, null, null, null, null);
Log.i(LOG_TAG,cursor.getCount()+" rows");
if(cursor.getCount()>0){
while(cursor.moveToNext()){
Reminders reminders = new Reminders();
reminders.setId(cursor.getLong(cursor.getColumnIndex(ReminderDBOpenHelper.COLUMN_ID)));
reminders.setTitle(cursor.getString(cursor.getColumnIndex(ReminderDBOpenHelper.COLUMN_TITLE)));
reminders.setDescription(cursor.getString(cursor.getColumnIndex(ReminderDBOpenHelper.COLUMN_DESCRIPTION)));
reminders.setLat(cursor.getDouble(cursor.getColumnIndex(ReminderDBOpenHelper.COLUMN_LAT)));
reminders.setLng(cursor.getDouble(cursor.getColumnIndex(ReminderDBOpenHelper.COLUMN_LONG)));
reminder.add(reminders);
}
}
you are missing
builder.setSmallIcon(R.drawable.remindericon);
the notification will not appear without this. And forillegalargumentexception contentintent required notifiction
try attaching pending intent.