J'essaie d'avoir un intentservice fonctionnant comme je l'ai fait avec un service de localisation d'économiser dans un fichier parfaitement.android studio intentservice ne fonctionne pas en dehors de l'application
Le service affiche une notification lorsqu'un fichier se trouve dans un répertoire. cela fonctionne bien dans une activité mais ne fonctionne pas quand je ferme.
Voici mon 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 " + "[email protected]")
.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);
}
}
Je ne peux pas trouver tout ce qui me manque ... Merci pour votre aide
quelle version d'Android que vous tester sur –
Je suis encore sur 5.1 maintenant – filoman
comment voulez-vous le service d'incendie intention? – Vyacheslav