Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This project can show the notification every 10000 seconds after setting the time using AlarmManager. </p> <p><strong>AlarmActivityActivity.java:</strong></p> <pre><code>package co.in.technoguys.AlarmActivity; import java.util.Calendar; import android.app.Activity; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.DatePicker; import android.widget.TimePicker; import android.widget.Toast; public class AlarmActivityActivity extends Activity { int notifyID=1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void startAlert(View view) { TimePicker tp=(TimePicker)findViewById(R.id.timePicker1); DatePicker dp=(DatePicker)findViewById(R.id.datePicker1); Calendar Cal = Calendar.getInstance(); Cal.set(Calendar.YEAR, dp.getYear()); Cal.set(Calendar.MONTH, dp.getMonth()); Cal.set(Calendar.DAY_OF_MONTH, dp.getDayOfMonth()); Cal.set(Calendar.HOUR_OF_DAY, tp.getCurrentHour()); Cal.set(Calendar.MINUTE, tp.getCurrentMinute()); Cal.set(Calendar.SECOND, 00); long when=Cal.getTimeInMillis(); Intent intent = new Intent(this, MyBroadcastReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 234324243, intent, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,when,20000,pendingIntent); Toast.makeText(this, "Notification Triggered on"+tp.getCurrentHour()+":"+tp.getCurrentMinute(), Toast.LENGTH_LONG).show(); } } </code></pre> <p><strong>MyBroadcastReceiver.java:</strong></p> <pre><code>package co.in.technoguys.AlarmActivity; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class MyBroadcastReceiver extends BroadcastReceiver { int notifyID=1; @Override public void onReceive(Context context, Intent intent) { Intent i=new Intent(); PendingIntent pi=PendingIntent.getBroadcast(context,0,i,0); NotificationManager nm=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notify=new Notification(R.drawable.ic_launcher,"Notification Triggered",System.currentTimeMillis()); CharSequence from="Remainder"; CharSequence message="Meeting Starts at 9 A.M"; notify.setLatestEventInfo(context, from, message, pi); nm.notify(notifyID,notify); } } </code></pre> <p><strong>main.xml:</strong> </p> <pre><code> &lt;TimePicker android:id="@+id/timePicker1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" /&gt; &lt;DatePicker android:id="@+id/datePicker1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/timePicker1" android:layout_alignLeft="@+id/timePicker1" android:layout_marginBottom="27dp" /&gt; &lt;Button android:id="@+id/startAlert" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/timePicker1" android:layout_below="@+id/timePicker1" android:layout_marginTop="36dp" android:onClick="startAlert" android:text="@string/count" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p><strong>AndroidManifest.xml:</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="co.in.technoguys.AlarmActivity" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="10" /&gt; &lt;uses-permission android:name="android.permission.VIBRATE" &gt; &lt;/uses-permission&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" &gt; &lt;activity android:name=".AlarmActivityActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;receiver android:name="MyBroadcastReceiver" &gt; &lt;/receiver&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload