매일 오전 6시에 내 앱이 "좋은 아침"메시지와 함께 알림을 표시하도록합니다. 내가 읽었을 때, 나는 앱을 백그라운드에서 실행해야하므로 서비스를 사용해야한다.지정된 시간에 매일 알림을 생성하는 서비스
다음 코드를 시도했지만 막혔습니다.
MainActivity.java
public void onClickStartService(View v)
{
startService(new Intent(this,MyService.class));
}
public void onClickStopService(View v)
{
stopService(new Intent(this,MyService.class));
}
및 MyService.java 내가 시작하고 서비스를 중지하는 버튼이 있고 작동
public class MyService extends Service{
private static final String TAG = "MyService";
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
Toast.makeText(this, "Congrats! MyService Created", Toast.LENGTH_LONG).show();
Log.d(TAG, "onCreate");
}
@Override
public void onStart(Intent intent, int startId) {
Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
Log.d(TAG, "onStart");
//Note: You can start a new thread and use it for long background processing from here.
}
@Override
public void onDestroy() {
Toast.makeText(this, "MyService Stopped", Toast.LENGTH_LONG).show();
Log.d(TAG, "onDestroy");
}
}
입니다. 이제는 게시물의 시작 부분에서 언급 한 것처럼 서비스에서 알림을 생성하려고합니다. 어떻게해야합니까?