나는 이것을 위해 3 일을 검색했습니다. 나는 밖으로 거기에 모든 솔루션을 시도 구글 및 stackoverflow.com.AlarmManager는 응용 프로그램이 시작될 때마다 작동합니다
저는 MainActivity
입니다.이 부분은 BroadcastReceiver
입니다.
Calendar calendar3 = Calendar.getInstance();
calendar3.set(Calendar.HOUR_OF_DAY, 7);
calendar3.set(Calendar.MINUTE, 34);
calendar3.set(Calendar.SECOND, 00);
Intent intent = new Intent(MainAcitivty.this, BroadCastReciver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(MainAcitivty.this, 0, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC, calendar3.getTimeInMillis(), pendingIntent);
나는 행운도없이 alarmManager.setReapeating
을 시도했다.
Intent i = new Intent(context,MyService.class);
context.startService(i);
서비스
public class MyService extends Service {
MyDB db;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.e("Yamen", "service Started");
db = new MyDB(getApplicationContext());
GregorianCalendar calendar = new GregorianCalendar();
Date time = calendar.getTime();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy");
String timeString = simpleDateFormat.format(time);
SharedPreferences mySharedPreferences = getApplicationContext().getSharedPreferences("myPref",Context.MODE_PRIVATE);
boolean isNoti=mySharedPreferences.getBoolean("isNoti",true);
if (isNoti) {
ArrayList<AnniBean> annis =
db.getAnni(timeString);
Log.e("Yamen", "size is " + annis.size());
for (AnniBean anni : annis) {
new NotificationCreator(getApplicationContext(), "Anniversary Reminder", anni.getAnniName(), anni.getAnniDetails());
}
}
Log.e("Yamen", "service finished");
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
}
notification
34 초에 매일 나타납니다
그런 다음 BroadcastReceiver
는 DB에서 일부 정보를 얻고 이런 notification
이상에 넣어 service
을 시작합니다 매력과 같습니다. 문제는 BroadcastReceiver
이고 service
은 응용 프로그램을 열 때마다 호출됩니다.
많은 링크를 방문했기 때문에 어떤 링크도 참조하지 마십시오. 조언에 감사드립니다.
시도가 아직 설정 여부를 응용 프로그램에 다시 –
을 알람을 설정하기 전에'PendingIntent.FLAG_NO_CREATE'을 사용하기 시작 자사의 –
후 방송 수신기 코드 및 매니페스트 –