我试图让一个intentservice像我一样在一个文件中完美保存位置服务。android studio intentservice没有在应用程序之外运行
当文件出现在目录中时,服务会弹出通知。 这很好地在一个活动内工作,但不关闭时。
这里是我的代码:
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);
}
}
我不能找到我缺少的是什么... 感谢您的帮助
我的是什么版本你 –
测试的Android仍然在5.1现在 – filoman
你怎么火的意图服务? – Vyacheslav