0
我試圖對我的大學進行Android操作,並且卡在報警部分。當您獲得由警報確定的時間時,我需要發送警報並可以打開另一個通知活動。如何通過廣播接收器啓動活動性
但是,由於類已經擴展了BroadcastReceiver,我該如何啓動另一個靈活性?
我的班級是這樣的:
public class ReceiverAlarme extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//inicia a Activity do Treino
Intent itTreino = new Intent(this, telaTreino.class);
//Does not work
//startActivity(itTreino);
//tentei fazer uma notificação que abrisse o programa, mas não rolou
Notification.Builder notificacao = new Notification.Builder(this);
notificacao.setDefaults(Notification.DEFAULT_ALL)
.setSmallIcon(android.R.drawable.ic_dialog_email)
.setContentTitle("Agendamento do teste")
.setContentText("Você tem um teste agendado!")
.setContentIntent(PendingIntent.getActivities(getApplicationContext(), 1, itTreino, PendingIntent.FLAG_CANCEL_CURRENT));
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(1, notificacao.build());
}
}
我建議你也給用戶與堅持的選擇'Notification',可能使用'setPriority()'。並非所有的用戶都希望他們的鬧鐘應用能夠接管前臺,特別是在設備正在使用的情況下。 – CommonsWare