My little alarm clock.

Source: Internet
Author: User

public class Mainactivity extends Activity {

@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Skip to Service
Intent intent=new Intent (this,alarmclockserivce.class);
StartService (Intent);

}
}

public class Alarmclockserivce extends Intentservice {

Public Alarmclockserivce () {
Super ("Overriding parent class Intentservice");

}

@Override
protected void Onhandleintent (Intent Intent) {//This is a sub-thread and no longer shuts down
Alarmmanager Alarmmanager = (alarmmanager) getsystemservice (Alarm_service);

Long Triggerattime=systemclock.elapsedrealtime () +1*60*1000;//1min after execution

Intent i=new Intent (this,alarmclockreceiver.class);
Pendingintent Pi=pendingintent.getbroadcast (this, 0, I, 0);

Alarmmanager.set (Alarmmanager.elapsed_realtime_wakeup, Triggerattime, pi);

LOG.I ("Current Time", System.currenttimemillis () + "");

}

public class Alarmclockreceiver extends Broadcastreceiver {

@Override
public void OnReceive (context context, Intent Intent) {

Notificationmanager Notificationmanager = (notificationmanager) context
. Getsystemservice (Context.notification_service);
Notification Notification = new Notification.builder (context)
. Setticker ("alarm alert"). Setcontenttitle ("Wake Up Time")
. Setcontenttext ("Master, there is an important date today.")
. Setsmallicon (Android. R.drawable.btn_star)
. Setvibrate (New long[]{0,2000,1000,2000,1000,2000,1000})
. build ();

Notificationmanager.notify (1, notification);

Intent i = new Intent (context, alarmclockserivce.class);
Context.startservice (i);

}

}

My little alarm clock.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.