내 응용 프로그램 내에서 사용자는 특정 시간을 설정할 수 있습니다. 응용 프로그램이 현재 실행되고 있는지 여부와 상관없이 시간이 설정 시간 (기본적으로 알람)에 도달하면 알림이 화면에 표시되기를 바랍니다.android에서 알람을위한 백그라운드 서비스를 실행 중이십니까?
어떻게해야합니까?
내 응용 프로그램 내에서 사용자는 특정 시간을 설정할 수 있습니다. 응용 프로그램이 현재 실행되고 있는지 여부와 상관없이 시간이 설정 시간 (기본적으로 알람)에 도달하면 알림이 화면에 표시되기를 바랍니다.android에서 알람을위한 백그라운드 서비스를 실행 중이십니까?
어떻게해야합니까?
긴 대답에 점점 미사용, 당신은 분명히
http://developer.android.com/reference/android/app/AlarmManager.html
확인 지금 내가 코드를 업데이트 한 ... 많은 검색하지 않았다.
다음은 CountDownTimer의 코드입니다. 시간이 완료되면 알림을 보냅니다. 서비스 또는 일반적인 활동에서 사용할 수 있습니다.
public String ns = Context.NOTIFICATION_SERVICE;
public NotificationManager mNotificationManager;
Notification notification;
PendingIntent contentIntent;
Intent notificationIntent;
public class Main extends Activity{
private final long startTime = 50000;
private final long interval = 1000;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
int time=Integer.parseInt(editText.getText().toString());
time=time*1000;
startTime = time;
// place this code on button listener if you want.
countDownTimer = new MyTimer(startTime, interval);
}
}
public class MyTimer extends CountDownTimer
{
public MyTimer(long startTime, long interval)
{
super(startTime, interval);
}
@Override
public void onFinish()
{
mNotificationManager = (NotificationManager) getSystemService(ns);
notificationIntent = new Intent(this, MyActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification = new Notification(R.drawable.icon,"Time up..", System.currentTimeMillis());
notification.setLatestEventInfo(this, "CallingaCab", "YOUR TIME COMPLETED", contentIntent);
mNotificationManager.notify(0, notification);
startActivity(notificationIntent);
}
@Override
public void onTick(long millisUntilFinished)
{
//Perform what do you want on each tick.
}
}
}
서비스를 백그라운드로 실행하는 서비스 클래스를 확장하고 원하는 것을 확인하십시오. here you can find service example.
카운트 다운 타이머 내에서 활동을 시작하려면 어떻게해야합니까? – molleman
또한 getSystemService에 전달할 수있는 대상은 무엇입니까? NS? – molleman
지금 확인해보십시오. 코드를 업데이트했습니다. – Noby