I'm trying to have an intentservice working like I did with a location service saving within a file perfectly.
The service pops up a notification when a file occurs in a directory. this works nicely inside an activity but doesn't when I close.
Here is my code :
public class NotifyService extends IntentService {
public NotifyService() {
super("NotifyService");
}
@Override
protected void onHandleIntent(Intent intent) {
File alerte = new File(Environment.getExternalStorageDirectory() +
File.separator +"SmartCollecte"+File.separator+ "ALERTE"+File.separator+ "IN"+File.separator+"alerte");
if(alerte.exists()){
createNotification();
}
else{}
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void createNotification() {
Intent intent = new Intent(this, NotificationReceiverActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
Notification noti = new Notification.Builder(this)
.setContentTitle("nouvelle collecte " + "test@gmail.com")
.setContentText("une nouvelle collecte est disponible").setSmallIcon(R.drawable.notification)
.setContentIntent(pIntent)
.setSmallIcon(R.drawable.notification)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);
}
}
I can't just find what I'm missing... Thanks for your help