Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

206
Visualizações
How to set specific time in Toast?

Can I display a toast message based on user's current time?

I need to make an app, Where when I open the screen from 1:00 am to 11:00 am it will display the toast message "Good morning" whereas if I open the screen at 6:00 pm to 11:00 pm it will display the toast "good night"

public class ToastDisplay extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)){
            Toast.makeText(context,"Good Morning",Toast.LENGTH_SHORT).show();
        }
    }
}
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

int toastDurationInMilliSeconds = 10000;

Toast.LENGTH_SHORT is int, so you have to declare new int

over 4 years ago · Santiago Trujillo Relatório

0

What you can do i use Calendar class to get the current time. Check the time and display the toast accordingly.

Calendar currentTime = Calender.getInstance();
int hour = currentTime.get(Calendar.HOUR_OF_DAY);

if(Use your condition here) {
    Display toast
} else if(Use your other condition) {
    Display toast
}

Just a note, your hour would be in 24 hour format so you need to check keeping that in mind.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda