I have written some related code for AlarmManager App and a Toast Massage is shown in onReceive method in the BroadcastReceiver class. this is ok so for...
now i want to do something like writting a Toast massage in the activity, for sure i can not do that in onReceive method the question is that how can i do it in the activity?
now i want to do something like writting a Toast massage in the activity, for sure i can not do that in onReceive method the question is that how can i do it in the activity?
Code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vv();
setRecurringAlarm(this);
// dateShow();
// prefss();
}
private void setRecurringAlarm(Context context) {
Calendar updateTime = Calendar.getInstance();
//updateTime.setTimeZone(TimeZone.getTimeZone("GMT+5:00"));
updateTime.setTimeZone(java.util.TimeZone.getTimeZone("GMT+5:00"));
updateTime.set(Calendar.HOUR_OF_DAY,5);
//updateTime.set(Calendar.MINUTE,31);
updateTime.set(Calendar.MINUTE,49);
updateTime.set(Calendar.SECOND,10);
Intent intent = new Intent(context, BroadConnect.class);
PendingIntent recurringDownload = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarms.setInexactRepeating(AlarmManager.RTC_WAKEUP, updateTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY, recurringDownload);
}
Code:
public class BroadConnect extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context,"ok" ,Toast.LENGTH_LONG).show();
}
}