android


push notification repearting for every second


Hi guys i am trying to create the push notification using the alarm manager where push notification must come at morning 8AM everything is good but notification is also coming but after 8AM notification is completed the notification coming when ever i open the App or clear from recents or for every one hour notification is coming please help me out facing this problem from last 1 Week
MainActivity.class
am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent notificationintent = new Intent(this, Notify.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 100, notificationintent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationintent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
Calendar calnotify = Calendar.getInstance();
Calendar now=Calendar.getInstance();
//Time Alaram manager
calnotify.set(Calendar.HOUR_OF_DAY, 10);
calnotify.set(Calendar.MINUTE, 00);
calnotify.set(Calendar.SECOND, 0);
if (now.after(calnotify)){
calnotify.add(Calendar.DATE,1);
}
am.setRepeating(AlarmManager.RTC_WAKEUP, calnotify.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
Notify.class
//BroadCastReceiver class
public class Notify extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent pushservice=new Intent(context,PushNotification.class);
pushservice.setData((Uri.parse("custom://"+System.currentTimeMillis())));
context.startService(pushservice);
}
}
PushNotification.class
public class PushNotification extends Service {
#Nullable
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onCreate() {
super.onCreate();
Resources resources = getResources();
getnotify(resources);
}
#Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
Resources resources = getResources();
getnotify(resources);
/*Notify notify=new Notify();
notify.abortBroadcast();*/
}
private void getnotify(Resources resources) {
Bitmap icon = BitmapFactory.decodeResource(resources,
R.drawable.sr_notification_icon);
PugNotification.with(this)
.load()
.title(getResources().getString(R.string.app_name))
.message("Latest Chitka")
.bigTextStyle(getResources().getString(R.string.app_name))
.smallIcon(getNotificationIcon())
.largeIcon(icon)
.flags(android.app.Notification.DEFAULT_ALL).autoCancel(true).click(MyCalendarActivity.class)
.simple()
.build();
}
private int getNotificationIcon() {
boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
return useWhiteIcon ? R.drawable.sr_icon : R.drawable.sr_notification_icon;
}
}
Looks like the code for setting alarm is executing multiple times as it is called from the main Activity of the application. You should set a flag that gets set to true once the alarm is set. Next time skip the alarm setting based on this flag.

Related Links

Set label above discrete steps seekbar
Exporting contacts from Android to Gmail account
Move From Video View to Scene in Android
Voltage and Temperature readout - Order of Magnitude issue
HttpURLConnection, how to sending parameters via post?
Reusing or appending the same TextViews, EditText boxes on next line in the same activity on pressing a button in android
Loading Large Images on WebView Causing Application Crash
Android EditText : getting entered text
Android: AdMob settings
Custom list displayed is empty
Android ListView on display/initialized event
Can we display Notifications in our activity other than status bar?
Image in html of TextView not being displayed properly
Schedule notification not triggered
How to load list into another activity's layout?
ProgressDialog firing only after setContentView()

Categories

HOME
httparty
polymer
ggplot2
css3
rsa
shiro
javacc
yandex
rds
emscripten
data-visualization
teechart
g++
mel
pega
rtf
scrolltop
do-while
scsi
feathersjs
sencha-touch
visual-glitch
roslyn
expressionengine3
oculus
quantlib
alm
mobx
glib
dsx-desktop
vue-chartjs
indy10
searchkit
google-earth-engine
dm-script
z-notation
recurrent-neural-network
metawidget
google-data-api
levenshtein-distance
avcapturedevice
term
hammer.js
podscms
jqchart
gpg-signature
branch-prediction
winusb
uicolor
x-tag
hclust
respondcms
aurora
yajsw
cortex-m
grass
avisynth
flock
zen-cart
uncompress
amiga
haskell-warp
sha512
rdflib
bufferedinputstream
jquery-forms-plugin
cakephp-2.7
dot.js
packet-sniffers
psr-4
imagefilter
authlogic
decoupling
windows-embedded-standard
gwt-openlayers
light
embedded-fonts
ice-cube
http-status-code-410
midlet
monotouch.dialog
node-redis
xcelsius
listactivity
timthumb
unattended-processing
appledoc
diagrams
non-clustered-index
office-2007
online-storage

Resources

Encrypt Message