2011-03-15 14 views
3

私のアンドロイドアプリケーションでは、私はプログラムでalaramを設定したいと思います。 アラームを正しく設定していますが、アラームを受信したときにこれに通知を適用するにはどうすればよいですか。アラーム受信機に通知を設定するandroid

私は開発者ガイドの通知を受けました。

コードを見つけてください。

Calendar cal=Calendar.getInstance(); 
    Intent alaram=new Intent(Alarmmanager.this,GroupsCheckAlarmReceiver.class); 
    PendingIntent pendingIntent = PendingIntent.getBroadcast(Alarmmanager.this, 0, alaram,0); 
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); 
    alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),pendingIntent); 
    cal.setTimeInMillis(System.currentTimeMillis()); 

    sendBroadcast(alaram,"setalaram"); 

及び放送受信機

public class GroupsCheckAlarmReceiver extends BroadcastReceiver{ 

@Override 
public void onReceive(final Context context, Intent intent) { 
Toast.makeText(context, "Alarm worked.", Toast.LENGTH_LONG).show(); 

} 

にそれが正常に動作しているが、私は唯一の活動の拡張クラスで正常に動作通知マネージャを設定する必要が通知を設定するには、どのように私は、受信および通知でそれを使用することができます。

貴重なご意見をお寄せください。事前に

感謝:)

答えて

6

私はあなたがNotificationManagerを見つけ、notifyを呼び出すためにonReceiveであなたのcontextを使用することができると思う:

@Override 
public void onReceive(Context context, Intent intent) { 
    NotificationManager notifications = (NotificationManager) 
     context.getSystemService(Context.NOTIFICATION_SERVICE); 
    notifications.notify(...); 
} 

あなたはContextを持っている場合は、何でもちょうど行うことができます! :)

+0

お返事いただきありがとうございます。 – Remmyabhavan

+1

どうすればよいですか? context.getSystemService(...)を実行することはできませんか? –

+1

あなたは 'Activity'でできることのほとんどを' Context'でも行うことができます。 –

0

BuzzBox SDKを使用するだけで、タスクのスケジュール設定や通知の作成が便利です。定期的なタスクをスケジュールするためのcrontab文字列をサポートしています。 BuzzBox SDK Website

関連する問題