푸시 알림을 사용하여 사용자에게 everymorning을 생각 나게하는 앱을 만들려고합니다.매일 아침에 사용자를 떠올리게하는 안드로이드 앱
저는 AlarmManager, BroadcastReceiver 및 IntentService를 사용하고 있습니다.
아래의 코드에서는 AlarmManager를 60 초 간격으로 테스트합니다.
문제 : 내 응용 프로그램을 종료 할 때까지 아무런 문제가 없으며 더 이상 경보가 발사되지 않습니다.
다음에 어떤 아이디어가 있습니까?
매니페스트 :
<service
android:name=".IntentMentor"
android:exported="false" >
</service>
<receiver android:name=".AlertReceiver"
android:process=":remote">
</receiver>
MainActivity :
Intent intent = new Intent(getApplicationContext(), AlertReceiver.class);
final PendingIntent pIntent = PendingIntent.getBroadcast(this, 0,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
long firstMillis = System.currentTimeMillis();
AlarmManager alarm = (AlarmManager)this.getSystemService(Context.ALARM_SERVICE);
// 1s is only for testing
alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, firstMillis, 1000*60, pIntent);
광기 :
public class AlertReceiver extends BroadcastReceiver {
private static final String TAG = "MyReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "MyReceiver on receive");
Intent i = new Intent(context, IntentMentor.class);
context.startService(i);
}
}
IntentService :
public class IntentMentor extends IntentService {
NotificationManager notificationManager;
int notifID = 33;
private static final String TAG = "MonitorService";
public IntentMentor() {
super(TAG);
}
@Override
protected void onHandleIntent(Intent intent) {
Log.d("TAG", "Service method was fired.");
pushNotification();
}
public void pushNotification(){
NotificationCompat.Builder notificBuilder = new NotificationCompat.Builder(this);
notificBuilder.setContentTitle("test");
notificBuilder.setContentText("this is text");
notificBuilder.setTicker("this is Ticker?");
notificBuilder.setSmallIcon(R.drawable.ic_info_black_24dp);
notificBuilder.setDefaults(NotificationCompat.DEFAULT_SOUND);
Intent intent = new Intent(this, Card.class);
TaskStackBuilder tStackBuilder = TaskStackBuilder.create(this);
tStackBuilder.addParentStack(Card.class);
tStackBuilder.addNextIntent(intent);
PendingIntent pendingIntent = tStackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
notificBuilder.setContentIntent(pendingIntent);
notificationManager = (NotificationManager) getSystemService((Context.NOTIFICATION_SERVICE));
notificationManager.notify(notifID, notificBuilder.build());
}
}
[도움을 받으실 수 있습니다] (http://stackoverflow.com/questions/35121191/i-want-show-notification-at-800-am-everyday/35127736#35127736) –
해결책을 찾으려했는데 귀하의 링크 뒤에. 고마워.하지만 난 아직도 같은 문제가있어. 앱이 열려 있지 않으면 알람이 실행되지 않습니다. – Wiltson
WAKE_LOCK –