サービスクラスを拡張するBackgroundServiceクラスを作成しました。Androidステータス通知
私はチェックの間の継続時間を記録するタイマーを持っています。 onCreateメソッドでは10秒間設定していますので、10秒ごとにステータス通知メッセージを送信することが予想されます。私が抱えている問題は、10秒ごとに、私はそれを有効にした状態通知を「サウンド」と聞いていますが、最初の通知サービスアラートにのみ表示される画面上部にテキストリマインダーは表示されません。誰もがこれを修正する方法を知っていますか?
このクラスのソースは、次のとおりです。ありがとうございました!
プライベートタイマータイマー;
private TimerTask updateTask = new TimerTask() {
@Override
public void run() {
Log.i(TAG, "Timer task doing work!");
// Process junk here:
sendNotification("Please leave in 5 min!!!");
}
};
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
Log.i(TAG, "Background Service creating");
timer = new Timer("DurationTimer");
timer.schedule(updateTask, 1000L, 10*1000L);
}
public void sendNotification(CharSequence message)
{
// Execute Check and Notify
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.simon;
CharSequence tickerText = message;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "LEAVE NOW!";
CharSequence contentText = "LEAVE NOW!!";
Intent notificationIntent = new Intent(this, BackgroundService.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.defaults |= Notification.DEFAULT_SOUND;
//notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);
}
caanあなたが受け入れられたコードをどこに追加したか教えてください。 – user3233280