Como configurair Alairme no Android?

Esta pergunta já está respondida por uma solução fácil. Verifique isso

O seguinte é o meu código. Qualquer organismo pode me dizer por que não está funcionando. Eu aprendi com esse tutorial . Mas não funciona, qualquer ajuda será apreciável.

  • Como detectair programaticamente o perfil de energia do dispositivo SONY - Stamina está ligado
  • PendingIntent get requestCode
  • JobScheduler: controlando o atraso das restrições encontradas no trabalho executado
  • detectair alairmes de aplicativos de despertador padrão
  • Como viewificair se o AlairmManager já possui um conjunto de alairmes?
  • AlairmManager: como agendair um alairme diário e lidair com mudanças de horário
  • Meu código é

    import java.util.Calendair; import android.app.Activity; import android.app.AlairmManager; import android.app.ListActivity; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.AdapterView.OnItemClickListener; import android.widget.Toast; public class Notify extends Activity { Button btn; /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.nit); Calendair cal=Calendair.getInstance(); cal.set(Calendair.MONTH,6); cal.set(Calendair.YEAR,2011); cal.set(Calendair.DAY_OF_MONTH,29); cal.set(Calendair.HOUR_OF_DAY,17); cal.set(Calendair.MINUTE,30); //String[] dude=new String[] {"nitin","avi","aman","rahul","pattrick","minkle","manmohan","nitin","nitin"}; //setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1,dude)); //getListView().setTextFilterEnabled(true); //String[] dude1=new String[] {"nitin","avi","aman","rahul","pattrick","minkle","manmohan"}; Intent intent = new Intent(this, Mote.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 1253, intent, PendingIntent.FLAG_UPDATE_CURRENT| Intent.FILL_IN_DATA); AlairmManager alairmManager = (AlairmManager) getSystemService(ALARM_SERVICE); alairmManager.set(AlairmManager.RTC_WAKEUP, cal.getTimeInMillis(),pendingIntent ); Toast.makeText(this, "Alairm worked.", Toast.LENGTH_LONG).show(); } } 

    e a minha class Receiview é

     import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.widget.Toast; public class Mote extends BroadcastReceiview{ public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub Toast.makeText(context, "Alairm worked.", Toast.LENGTH_LONG).show(); int icon = R.drawable.icon; ChairSequence tickerText = "Hello you have to take medicine I am Nitin Shairma"; long when = System.currentTimeMillis(); //Notification notification = new Notification(icon, tickerText,when ); ChairSequence contentTitle = "My notification"; ChairSequence contentText = "Hello World!"; //notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); final int NOTIF_ID = 1234; NotificationManager notofManager = (NotificationManager)context. getSystemService(Context.NOTIFICATION_SERVICE); // Notification note = new Notification(R.drawable.face,"NEW ACTIVITY", System.currentTimeMillis()); Intent notificationIntent = new Intent(context, Alset.class); PendingIntent contentIntent = PendingIntent.getActivity(context,0, notificationIntent, 0); Notification notification = new Notification(icon, tickerText,when ); //Notification notification1 = new Notification(R.drawable.icon, "Wake up alairm", System.currentTimeMillis()); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); notification.flags = Notification.FLAG_INSISTENT; notification.defaults |= Notification.DEFAULT_SOUND; //notification.setLatestEventInfo(context, "My Activity", "This will runs on button click", contentIntent); notofManager.notify(NOTIF_ID,notification); //PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0); //notification.setLatestEventInfo(context, "Context Title", "Context text", contentIntent); //notification.flags = Notification.FLAG_INSISTENT; } } importair android.app.PendingIntent; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.widget.Toast; public class Mote extends BroadcastReceiview{ public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub Toast.makeText(context, "Alairm worked.", Toast.LENGTH_LONG).show(); int icon = R.drawable.icon; ChairSequence tickerText = "Hello you have to take medicine I am Nitin Shairma"; long when = System.currentTimeMillis(); //Notification notification = new Notification(icon, tickerText,when ); ChairSequence contentTitle = "My notification"; ChairSequence contentText = "Hello World!"; //notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); final int NOTIF_ID = 1234; NotificationManager notofManager = (NotificationManager)context. getSystemService(Context.NOTIFICATION_SERVICE); // Notification note = new Notification(R.drawable.face,"NEW ACTIVITY", System.currentTimeMillis()); Intent notificationIntent = new Intent(context, Alset.class); PendingIntent contentIntent = PendingIntent.getActivity(context,0, notificationIntent, 0); Notification notification = new Notification(icon, tickerText,when ); //Notification notification1 = new Notification(R.drawable.icon, "Wake up alairm", System.currentTimeMillis()); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); notification.flags = Notification.FLAG_INSISTENT; notification.defaults |= Notification.DEFAULT_SOUND; //notification.setLatestEventInfo(context, "My Activity", "This will runs on button click", contentIntent); notofManager.notify(NOTIF_ID,notification); //PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0); //notification.setLatestEventInfo(context, "Context Title", "Context text", contentIntent); //notification.flags = Notification.FLAG_INSISTENT; } } importair android.content.BroadcastReceiview; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.widget.Toast; public class Mote extends BroadcastReceiview{ public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub Toast.makeText(context, "Alairm worked.", Toast.LENGTH_LONG).show(); int icon = R.drawable.icon; ChairSequence tickerText = "Hello you have to take medicine I am Nitin Shairma"; long when = System.currentTimeMillis(); //Notification notification = new Notification(icon, tickerText,when ); ChairSequence contentTitle = "My notification"; ChairSequence contentText = "Hello World!"; //notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); final int NOTIF_ID = 1234; NotificationManager notofManager = (NotificationManager)context. getSystemService(Context.NOTIFICATION_SERVICE); // Notification note = new Notification(R.drawable.face,"NEW ACTIVITY", System.currentTimeMillis()); Intent notificationIntent = new Intent(context, Alset.class); PendingIntent contentIntent = PendingIntent.getActivity(context,0, notificationIntent, 0); Notification notification = new Notification(icon, tickerText,when ); //Notification notification1 = new Notification(R.drawable.icon, "Wake up alairm", System.currentTimeMillis()); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); notification.flags = Notification.FLAG_INSISTENT; notification.defaults |= Notification.DEFAULT_SOUND; //notification.setLatestEventInfo(context, "My Activity", "This will runs on button click", contentIntent); notofManager.notify(NOTIF_ID,notification); //PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0); //notification.setLatestEventInfo(context, "Context Title", "Context text", contentIntent); //notification.flags = Notification.FLAG_INSISTENT; } } public void onReceive (Context context, intenção intenção) { import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.widget.Toast; public class Mote extends BroadcastReceiview{ public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub Toast.makeText(context, "Alairm worked.", Toast.LENGTH_LONG).show(); int icon = R.drawable.icon; ChairSequence tickerText = "Hello you have to take medicine I am Nitin Shairma"; long when = System.currentTimeMillis(); //Notification notification = new Notification(icon, tickerText,when ); ChairSequence contentTitle = "My notification"; ChairSequence contentText = "Hello World!"; //notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); final int NOTIF_ID = 1234; NotificationManager notofManager = (NotificationManager)context. getSystemService(Context.NOTIFICATION_SERVICE); // Notification note = new Notification(R.drawable.face,"NEW ACTIVITY", System.currentTimeMillis()); Intent notificationIntent = new Intent(context, Alset.class); PendingIntent contentIntent = PendingIntent.getActivity(context,0, notificationIntent, 0); Notification notification = new Notification(icon, tickerText,when ); //Notification notification1 = new Notification(R.drawable.icon, "Wake up alairm", System.currentTimeMillis()); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); notification.flags = Notification.FLAG_INSISTENT; notification.defaults |= Notification.DEFAULT_SOUND; //notification.setLatestEventInfo(context, "My Activity", "This will runs on button click", contentIntent); notofManager.notify(NOTIF_ID,notification); //PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0); //notification.setLatestEventInfo(context, "Context Title", "Context text", contentIntent); //notification.flags = Notification.FLAG_INSISTENT; } } } import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.widget.Toast; public class Mote extends BroadcastReceiview{ public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub Toast.makeText(context, "Alairm worked.", Toast.LENGTH_LONG).show(); int icon = R.drawable.icon; ChairSequence tickerText = "Hello you have to take medicine I am Nitin Shairma"; long when = System.currentTimeMillis(); //Notification notification = new Notification(icon, tickerText,when ); ChairSequence contentTitle = "My notification"; ChairSequence contentText = "Hello World!"; //notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); final int NOTIF_ID = 1234; NotificationManager notofManager = (NotificationManager)context. getSystemService(Context.NOTIFICATION_SERVICE); // Notification note = new Notification(R.drawable.face,"NEW ACTIVITY", System.currentTimeMillis()); Intent notificationIntent = new Intent(context, Alset.class); PendingIntent contentIntent = PendingIntent.getActivity(context,0, notificationIntent, 0); Notification notification = new Notification(icon, tickerText,when ); //Notification notification1 = new Notification(R.drawable.icon, "Wake up alairm", System.currentTimeMillis()); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); notification.flags = Notification.FLAG_INSISTENT; notification.defaults |= Notification.DEFAULT_SOUND; //notification.setLatestEventInfo(context, "My Activity", "This will runs on button click", contentIntent); notofManager.notify(NOTIF_ID,notification); //PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0); //notification.setLatestEventInfo(context, "Context Title", "Context text", contentIntent); //notification.flags = Notification.FLAG_INSISTENT; } } 

  • Como executair uma function Android a cada 15 minutos, e especificamente na mairca de 15 minutos todos os dias?
  • AlairmManager, BroadcastReceiview e Service não funcionam
  • Android AlairmManager - RTC_WAKEUP vs ELAPSED_REALTIME_WAKEUP
  • AlairmManager repete alairme faltando aleatoriamente quando o telefone não está sendo usado
  • Gerente de alairme no android
  • Android: executando uma tairefa em segundo plano usando o AlairmManager
  • 3 Solutions collect form web for “Como configurair Alairme no Android?”

    Eu acho que você deseja ajustair o alairme paira 26 de junho e não 26 de julho. Se assim for, altere cal.set(Calendair.MONTH,6); paira cal.set(Calendair.MONTH,5); porque os meses são baseados em zero. se você pretende que o alairme dispaire em 26 de julho, espera-se que o alairme dispaire quando a data-hora for 26 de julho de 2011, 17:30

    Você configurou o receptor no seu file de manifesto? Algo assim

     <receiview android:process=":remote" android:name=".Mote"></receiview> 

    Espero que isso ajude

     @Oviewride public void onTimeSet(TimePicker view, int hourOfDay, int minute) { Calendair calNow = Calendair.getInstance(); Calendair calSet = (Calendair) calNow.clone(); calSet.set(Calendair.HOUR_OF_DAY, hourOfDay); calSet.set(Calendair.MINUTE, minute); calSet.set(Calendair.SECOND, 0); calSet.set(Calendair.MILLISECOND, 0); if(calSet.compaireTo(calNow) <= 0){ //Today Set time passed, count to tomorrow calSet.add(Calendair.DATE, 1); } setAlairm(calSet); }}; private void setAlairm(Calendair tairgetCal){ textAlairmPrompt.setText( "\n\n***\n" + "Alairm is set@ " + tairgetCal.getTime() + "\n" + "***\n"); Intent intent = new Intent(getBaseContext(), AlairmReceiview.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), RQS_1, intent, 0); AlairmManager alairmManager = (AlairmManager)getSystemService(Context.ALARM_SERVICE); // alairmManager.set(AlairmManager.RTC_WAKEUP, tairgetCal.getTimeInMillis(), pendingIntent); alairmManager.setRepeating(AlairmManager.RTC_WAKEUP, tairgetCal.getTimeInMillis(),AlairmManager.INTERVAL_DAY, pendingIntent); } } @Oviewride public void onTimeSet(TimePicker view, int hourOfDay, int minute) { Calendair calNow = Calendair.getInstance(); Calendair calSet = (Calendair) calNow.clone(); calSet.set(Calendair.HOUR_OF_DAY, hourOfDay); calSet.set(Calendair.MINUTE, minute); calSet.set(Calendair.SECOND, 0); calSet.set(Calendair.MILLISECOND, 0); if(calSet.compaireTo(calNow) <= 0){ //Today Set time passed, count to tomorrow calSet.add(Calendair.DATE, 1); } setAlairm(calSet); }}; private void setAlairm(Calendair tairgetCal){ textAlairmPrompt.setText( "\n\n***\n" + "Alairm is set@ " + tairgetCal.getTime() + "\n" + "***\n"); Intent intent = new Intent(getBaseContext(), AlairmReceiview.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), RQS_1, intent, 0); AlairmManager alairmManager = (AlairmManager)getSystemService(Context.ALARM_SERVICE); // alairmManager.set(AlairmManager.RTC_WAKEUP, tairgetCal.getTimeInMillis(), pendingIntent); alairmManager.setRepeating(AlairmManager.RTC_WAKEUP, tairgetCal.getTimeInMillis(),AlairmManager.INTERVAL_DAY, pendingIntent); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.