0

I am making a app where I get a date-time from the database and then I want to use the time to set an alarm on the phone. Not on the app. The alarm should be set on the Phone's clock application (Android clock).

I searched the web and couldn't find any useful answers.

Please help. Thanks :D

Making my questions more understandable :-

My activity has a textview whos value is :- 2014-05-17 16:30

And it has a button.

When i click that button i want to set an alarm on the android clock on that time.

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
Soumil Deshpande
  • 1,622
  • 12
  • 14

1 Answers1

0

You receive the Text Filed Entry and Just Pass it to the Below function.

public class Alarm extends BroadcastReceiver 
 {    
 @Override
 public void onReceive(Context context, Intent intent) 
 {   
     PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
     PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"MyTag");
     wl.acquire();

     Toast.makeText(context, "Alarm !!!!!!!!!!", Toast.LENGTH_LONG).show();

     wl.release();
 }

 public void SetAlarm(Context context)
 {
     AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
     Intent i = new Intent(context, Alarm.class);
     PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
     am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 60 * 10, pi);
 }

 public void CancelAlarm(Context context)
 {
     Intent intent = new Intent(context, Alarm.class);
     PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
     AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
     alarmManager.cancel(sender);
 }
 }

And add this in the Manifest File :

<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
...
<receiver  android:process=":remote" android:name="Alarm"></receiver>
Bhargav
  • 227
  • 1
  • 11
  • I want the alarm in the alarm app which android has by default. Not on my app i.e If i set an alarm by my app, it should get set in the android app which the phone has by default. – Soumil Deshpande May 19 '14 at 08:35