Getting Method Not Found Settime(long) In Alarmmanager When Tried To Set Time And Date In Android System Time
I'm trying to set the system time and date on an Android device. I thought the following code would work, but it produces the error method not found: setTime(long) Calendar c = Cal
Solution 1:
It is not possible for an application to change the date or time on an (non-rooted) Android device.
From the documentation for AlarmManager.setTime()
:
Requires the permission android.permission.SET_TIME.
See http://developer.android.com/reference/android/app/AlarmManager.html
Solution 2:
This may Helpful ------------------Broad Cast Class----------------------------
publicclassTimeReceiverextendsBroadcastReceiver {
@OverridepublicvoidonReceive(Context ctx, Intent intent) {
Toast.makeText(ctx, "It's time to WAKE UP!!!!", Toast.LENGTH_SHORT).show();
}
}
----------------Write this code in Activity Class --------------------------
PendingIntent sender = null;
Intent intent = null;
Calendar systemtime = Calendar.getInstance();
systemtime.setTime(new Date());
Calendar timeToTriggerAlarm = Calendar.getInstance();
timeToTriggerAlarm.set(Calendar.HOUR_OF_DAY, systemtime.get(Calendar.HOUR_OF_DAY));
timeToTriggerAlarm.set(Calendar.MINUTE, systemtime.get(Calendar.MINUTE));
timeToTriggerAlarm.set(Calendar.SECOND, 00);
intent = new Intent(this,TimeReceiver.class);
sender = PendingIntent.getBroadcast(this, 0, intent,PendingIntent.FLAG_ONE_SHOT);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, timeToTriggerAlarm.getTimeInMillis(), sender);
Note- Opent your manifest file and click on option>Add>Reciever>brows>addclassname(here is TimeReceiver)
Post a Comment for "Getting Method Not Found Settime(long) In Alarmmanager When Tried To Set Time And Date In Android System Time"