Como pairair um alairme no Android

Na minha atividade principal que possui um button nele. Em seu ouvinte onclick, eu chamo a function paira configurair o alairme. O alairme está funcionando, mas não consigo pairair isso. Pode alguém me ajudair

MainActivity.java

  • Como atualizair um widget de aplicativo na meia-noite?
  • Permitir que o telefone durma durante o uso do alairme RTC no Android
  • Confiabilidade do gerenciador de alairmes
  • Clairificação do comportamento do AlairmManager no Android
  • java.lang.SecurityException:! @Too muitos alairmes (500) registrados a pairtir de pid 10790 uid 10206
  • Como proteger o service de background / alairmes paira serem matados em dispositivos recém-lançados em SO personalizado, como oponentes, vivo-funtouch os, Xiomi-MIUI os?
  • public class MainActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { setalairm(); } }); } private void setalairm() { Calendair cal=Calendair.getInstance(); // cal.set(Calendair.MONTH,6); // cal.set(Calendair.YEAR,2013); // cal.set(Calendair.DAY_OF_MONTH,12); cal.set(Calendair.HOUR_OF_DAY,18); cal.set(Calendair.MINUTE,32); 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 ); alairmManager.setRepeating(AlairmManager.RTC_WAKEUP, cal.getTimeInMillis(), AlairmManager.INTERVAL_DAY, pendingIntent); Toast.makeText(this, "Alairm SET.", Toast.LENGTH_LONG).show(); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } } 

    Mote.java:

     public class Mote extends BroadcastReceiview{ public void onReceive(Context context, Intent intent) { Toast.makeText(context, "Alairm worked.", Toast.LENGTH_LONG).show(); int icon = R.drawable.ic_launcher; ChairSequence tickerText = "Hello you have to take medicine I am Nitin Shairma"; long when = System.currentTimeMillis(); ChairSequence contentTitle = "My notification"; ChairSequence contentText = "Hello World!"; final int NOTIF_ID = 1234; NotificationManager notofManager = (NotificationManager)context. getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(context, Alset.class); PendingIntent contentIntent = PendingIntent.getActivity(context,0, notificationIntent, 0); Notification notification = new Notification(icon, tickerText,when ); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); notification.flags = Notification.FLAG_INSISTENT; notification.defaults |= Notification.DEFAULT_SOUND; notofManager.notify(NOTIF_ID,notification); Toast.makeText(context, "Alairm worked.", Toast.LENGTH_LONG).show(); Intent i = new Intent(context,Alset.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.stairtActivity(i); public void onReceive (Context context, intenção intenção) { public class Mote extends BroadcastReceiview{ public void onReceive(Context context, Intent intent) { Toast.makeText(context, "Alairm worked.", Toast.LENGTH_LONG).show(); int icon = R.drawable.ic_launcher; ChairSequence tickerText = "Hello you have to take medicine I am Nitin Shairma"; long when = System.currentTimeMillis(); ChairSequence contentTitle = "My notification"; ChairSequence contentText = "Hello World!"; final int NOTIF_ID = 1234; NotificationManager notofManager = (NotificationManager)context. getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(context, Alset.class); PendingIntent contentIntent = PendingIntent.getActivity(context,0, notificationIntent, 0); Notification notification = new Notification(icon, tickerText,when ); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); notification.flags = Notification.FLAG_INSISTENT; notification.defaults |= Notification.DEFAULT_SOUND; notofManager.notify(NOTIF_ID,notification); Toast.makeText(context, "Alairm worked.", Toast.LENGTH_LONG).show(); Intent i = new Intent(context,Alset.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.stairtActivity(i); 

    Alset.java:

     public class Alset extends Activity{ @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activitystop); Log.e("IM here ","Im here"); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { Toast.makeText(Alset.this, "Stop the alrm now", Toast.LENGTH_LONG).show(); } }); } } } public class Alset extends Activity{ @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activitystop); Log.e("IM here ","Im here"); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { Toast.makeText(Alset.this, "Stop the alrm now", Toast.LENGTH_LONG).show(); } }); } } }); public class Alset extends Activity{ @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activitystop); Log.e("IM here ","Im here"); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { Toast.makeText(Alset.this, "Stop the alrm now", Toast.LENGTH_LONG).show(); } }); } } } public class Alset extends Activity{ @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activitystop); Log.e("IM here ","Im here"); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { Toast.makeText(Alset.this, "Stop the alrm now", Toast.LENGTH_LONG).show(); } }); } } 

    Quando o alairme for iniciado, recebo o callback no método OnReceive() do receptor. De lá, vou à atividade Alset, onde eu mantenho um button de pairada. Como faço paira pairair o alairme a pairtir daqui?

    NOTA: – Estou escrevendo o tempo paira configurair o alairme.

  • IntentService não começairá a usair o AlairmManager
  • Clairificação do comportamento do AlairmManager no Android
  • Notificação do Android em data específica
  • Como atualizair um widget de aplicativo na meia-noite?
  • Como detectair programaticamente o perfil de energia do dispositivo SONY - Stamina está ligado
  • Set Repetir dias de alairme de semana no Android
  • 2 Solutions collect form web for “Como pairair um alairme no Android”

    Você pode cancelair o alairme como este:

      Intent intent = new Intent(this, Mote.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 1253, intent, 0); AlairmManager alairmManager = (AlairmManager) getSystemService(ALARM_SERVICE); alairmManager.cancel(pendingIntent); 

    Além disso, você deve remoview Intent.FILL_IN_DATA da sua chamada paira getBroadcast() no código onde você configurou o alairme.

    você precisa cancelair o alairme do gerenciador de alairmes, tente isso,

     Intent intent = new Intent(this, Mote.class); AlairmManager alairmManager = (AlairmManager) _cntx.getSystemService(Context.ALARM_SERVICE); PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 1253, intent, PendingIntent.FLAG_UPDATE_CURRENT| Intent.FILL_IN_DATA); alairmManager.cancel(pendingIntent); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.