Note that there are some explanatory texts on larger screens.

plurals
  1. POContinous notification after 2 minutes android
    primarykey
    data
    text
    <p>I want to show continuous notifications in my application.</p> <p>Currently I am able to raise notification automatically after 4sec but what I want is it should continuously raise after specific time interval.</p> <p>Following is my code. </p> <p>my xml file is</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" &gt; &lt;Button android:id="@+id/notify" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="Raise a notification" android:onClick="notifyMe" /&gt; &lt;Button android:id="@+id/cancel" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="Clear the notification" android:onClick="clearNotification" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>this is my activity file</p> <pre><code>package com.vimaltuts.android.notificationexample; import java.util.Timer; import java.util.TimerTask; import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; import android.os.Bundle; import android.view.View; public class NotificationExampleActivity extends Activity { private static final int NOTIFY_ME_ID=1987; private int count=0; private NotificationManager mgr=null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mgr=(NotificationManager)getSystemService(NOTIFICATION_SERVICE); Timer timer = new Timer(); timer.schedule(new TimerTask() { public void run() { View v = new View(getApplicationContext()); notifyMe(v); }},4000); } @SuppressWarnings("deprecation") public void notifyMe(View v) { @SuppressWarnings("deprecation") Notification note=new Notification(R.drawable.stat_notify_chat,"Status message!",System.currentTimeMillis()); PendingIntent i=PendingIntent.getActivity(this,0,new Intent(this, NotificationMessage.class),0); note.setLatestEventInfo(this, "New Email","Unread Conversation", i); note.number=++count; note.vibrate=new long[] {500L, 200L, 200L, 500L}; note.flags|=Notification.FLAG_AUTO_CANCEL; mgr.notify(NOTIFY_ME_ID, note); } public void clearNotification(View v) { mgr.cancel(NOTIFY_ME_ID); } } </code></pre> <p>Please tell me where should I need to have additional code if any?</p> <p>Also is it possible with service..how? </p> <hr> <p>i tried following code foe test purpose but it did't work...can anyone tell me where i goes wrong </p> <p>following is my activity code</p> <pre><code> Intent i= new Intent(NotificationExampleActivity.this,NotificationService.class); PendingIntent pi=PendingIntent.getService(NotificationExampleActivity.this, 0, i, 0); AlarmManager alarmMgr=(AlarmManager)getSystemService(ALARM_SERVICE); alarmMgr.cancel(pi); alarmMgr.setRepeating(alarmMgr.ELAPSED_REALTIME_WAKEUP, System.currentTimeMillis(),(10*1000), pi); Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show(); </code></pre> <p>And following is my broadcast reciver</p> <pre><code> Toast.makeText(context, "Repeating Alarm worked.", Toast.LENGTH_LONG).show(); </code></pre> <p>i want to display msg="Repeating Alarm worked" after some time intervel</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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