import java.util.Calendar;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class AlarmDemoActivity extends Activity {
private PendingIntent pendingIntent;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button buttonStart = (Button) findViewById(R.id.startalarm);
Button buttonCancel = (Button) findViewById(R.id.cancelalarm);
buttonStart.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent= new Intent(AlarmDemoActivity.this,MyAlarmService.class);
pendingIntent =PendingIntent.getService(AlarmDemoActivity.this,1, intent,1);
AlarmManager manager=(AlarmManager)getSystemService(Context.ALARM_SERVICE);
manager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+20000, pendingIntent);
//manager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 5*1000, pendingIntent);
}
});
buttonCancel.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View arg0) {
AlarmManager manager=(AlarmManager)getSystemService(Context.ALARM_SERVICE);
manager.cancel(pendingIntent);
}
});
}
}
MyAlarmService.java
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;
public class MyAlarmService extends Service {
@Override
public void onCreate() {
// TODO Auto-generated method stub
Toast.makeText(this, "MyAlarmService.onCreate()", Toast.LENGTH_LONG).show();
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
Toast.makeText(this, "MyAlarmService.onBind()", Toast.LENGTH_LONG).show();
return null;
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Toast.makeText(this, "MyAlarmService.onDestroy()", Toast.LENGTH_LONG).show();
}
@Override
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
Toast.makeText(this, "MyAlarmService.onStart()", Toast.LENGTH_LONG).show();
}
@Override
public boolean onUnbind(Intent intent) {
// TODO Auto-generated method stub
Toast.makeText(this, "MyAlarmService.onUnbind()", Toast.LENGTH_LONG).show();
return super.onUnbind(intent);
}
}
please send me this complete code of alarm on my mail id:
ReplyDeletesaparia.maharshi@gmail.com
can you please send me the complete code, this is my email :
ReplyDeleteabdellah.felahi@gmail.com
can u plz send me the complete code. it will be verymuch helpfull for me.
ReplyDeleteThanks in advance :) please do send it :)
email : ashwinimohan888@gmail.com
Please I need the Complete code very very Urgent ,i will be very grateful for u :) this is my email
ReplyDeletesamar.abou.abeed.saad@gmail.com
thanks very much for ur effort :)
May i have the complete code? ^^
ReplyDeleteEmail: Vivian63093@hotmail.com
ply send that complete code..
ReplyDeletehi sir ,
ReplyDeleteplease tell me this condition ... if i am set Alarm ... come out from out Activity .....
i will get particular alarm at time .
and how can i use the service code for that .... ?
Thanks
Govind Rao
please send this complete code to me..
ReplyDeletesamba.y8it866@gmail.com
This comment has been removed by the author.
ReplyDeleteplease send this complete code to me...
ReplyDeletehoconlineit@gmail.com
plz can u send this code at
ReplyDeleteprv.ashraf@gmail.com
plz send this code
ReplyDeleteankitsevakhr@gmail.com
please send this complete code
ReplyDeletestu.elitefriends@gmail.com
Can you please send this complete code
ReplyDeletemihir8589@gmail.com
Thanks in advance
DeleteCan you please send this complete code
Deletetaitien92@outlook.com
Can you please send this complete code
ReplyDeletetaitien92@outlook.com
please send me this complete code of alarm on my mail id:
ReplyDeletejavier-huchin@hotmail.com
can you please send this complete code giangphamvp@gmail.com
ReplyDeletecan u plz send complete code of this.....
ReplyDeletewaqar.vky14@gmail.com
this is my id....... thnx
can you please send this complete code:
ReplyDeletekhuatvannhan@gmail.com
Can someone send me complte code please. I need urgently it.
ReplyDeleteaslansemir@hotmail.con