2012-02-14 31 views
0

次のコードを記述します。 BroadcastRecieverをマニフェストで宣言しましたが、まだ動作していません。 私は初心者で2時間ぎっしり詰まっています。 ここにはどんな問題がありますか?アラームが作動しない

// My launcher activity 
public class AlarmMainActivity extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     AlarmManager am=(AlarmManager)getSystemService(Context.ALARM_SERVICE); 
     GregorianCalendar gc=new GregorianCalendar(); 
     gc.set(2012, 1, 14, 11, 28); 

     Intent intent=new Intent(this, AlarmService.class); 
     gc.set(Calendar.AM_PM, 0); 

     PendingIntent sender=PendingIntent.getBroadcast(this, 1, intent, 0); 
     am.set(AlarmManager.RTC_WAKEUP, gc.getTimeInMillis(), sender); 
     System.out.print(gc); 
    } 
} 

// broadcast reciever class 

public class AlarmService extends BroadcastReceiver { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     Toast.makeText(context, "Alarm started", 2000).show(); 
    } 
} 
+0

はStackOverflowのへようこそ。発生した特定のエラーや問題を示して、他の人があなたを助けることができるようにしてください。 – dbrin

答えて

0
NotificationManager nm; 
@Override 
public void onReceive(Context context, Intent intent) { 
    nm = (NotificationManager) context.getSystemService(
     Context.NOTIFICATION_SERVICE); 
    CharSequence from = "Check your ...."; 
    CharSequence message = "It's time!"; 
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, 
     new Intent(), 0); 
    Notification notif = new Notification(R.drawable.ic_launcher, 
     "ur text", System.currentTimeMillis()); 
    notif.setLatestEventInfo(context, from, message, contentIntent); 
    notif.defaults |= Notification.DEFAULT_SOUND; 
    notif.flags |= Notification.FLAG_AUTO_CANCEL; 
    nm.notify(1, notif); 
関連する問題