Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Error with Android local notfication

$
0
0

Hi all now i am using benCoding.alarmmanger and every thing is working fine when i am making a service ok and every service have a fixed time and alert at the time fine but the problem is every time i open the app all notfications notify when open app i wont the notfications at the time

var date = new Date();
date.setHours(05);
date.setMinutes(10);
alarmManager.addAlarmService({
    requestCode : 1001,
    service : 'com.midade.alfSona.NotificationService',
    year : date.getFullYear(),
    month : date.getMonth(),
    day : date.getDate(),
    hour : date.getHours(),
    minute : date.getMinutes(),
    repeat : 'daily',
});
 
// 6:50
var date_2 = new Date();
date_2.setHours(06);
date_2.setMinutes(50);
alarmManager.addAlarmService({
    requestCode : 1002,
    service : 'com.midade.alfSona.Notification_2Service',
    year : date_2.getFullYear(),
    month : date_2.getMonth(),
    day : date_2.getDate(),
    hour : date_2.getHours(),
    minute : date_2.getMinutes(),
    repeat : 'daily',
    //forceRestart:true  //You can use the words hourly,daily,weekly,monthly,yearly or you can provide milliseconds.
});
notfication.js
var activity = Ti.Android.currentActivity;
var intent = Ti.Android.createIntent({
    action : Ti.Android.ACTION_MAIN,
    className : 'com.midade.alfSona.AlfsonaActivity',
    flags : Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Ti.Android.FLAG_ACTIVITY_SINGLE_TOP
});
intent.addCategory(Titanium.Android.CATEGORY_LAUNCHER);
 
var pending = Ti.Android.createPendingIntent({
    activity : activity,
    intent : intent,
    type : Ti.Android.PENDING_INTENT_FOR_ACTIVITY,
    flags : Ti.Android.PENDING_INTENT_FOR_ACTIVITY
});
 
var notification = Ti.Android.createNotification({
    contentIntent : pending,
    contentTitle : Ti.App.Properties.getObject(Ti.App.Properties.getString('lang_code')).message_1,
    contentText : Ti.App.Properties.getObject(Ti.App.Properties.getString('lang_code')).title,
    tickerText : Ti.App.Properties.getObject(Ti.App.Properties.getString('lang_code')).title,
    sound : Ti.Android.DEFAULT_SOUND,
    when : new Date().getTime(),
    icon : Ti.App.Android.R.drawable.appicon,
    flags : Titanium.Android.ACTION_DEFAULT | Titanium.Android.FLAG_AUTO_CANCEL | Titanium.Android.FLAG_SHOW_LIGHTS
});
 
Ti.Android.NotificationManager.notify(1, notification);
 
var service = Ti.Android.currentService;
var serviceIntent = service.getIntent();
Ti.Android.stopService(serviceIntent);
// this will display that custom extra that we added when we created the intent
intent.putExtra('message', 'This is that little extra 1');
var teststring = serviceIntent.getStringExtra('message');
Ti.API.info('Extra!: ' + teststring);
 
//Ti.Android.stopService(serviceIntent);
notfication2.js
var activity = Ti.Android.currentActivity;
var intent = Ti.Android.createIntent({
    action : Ti.Android.ACTION_MAIN,
    className : 'com.midade.alfSona.AlfsonaActivity',
    flags : Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Ti.Android.FLAG_ACTIVITY_SINGLE_TOP
});
intent.addCategory(Titanium.Android.CATEGORY_LAUNCHER);
 
var pending = Ti.Android.createPendingIntent({
    activity : activity,
    intent : intent,
    type : Ti.Android.PENDING_INTENT_FOR_ACTIVITY,
    flags : Ti.Android.PENDING_INTENT_FOR_ACTIVITY
});
 
var notification = Ti.Android.createNotification({
    contentIntent : pending,
    contentTitle : Ti.App.Properties.getObject(Ti.App.Properties.getString('lang_code')).message_2,
    contentText : Ti.App.Properties.getObject(Ti.App.Properties.getString('lang_code')).title,
    tickerText : Ti.App.Properties.getObject(Ti.App.Properties.getString('lang_code')).title,
    sound:Ti.Filesystem.getResRawDirectory() + '/hamdlellah.mp3',
    when : new Date().getTime(),
    icon : Ti.App.Android.R.drawable.appicon,
    flags : Titanium.Android.ACTION_DEFAULT | Titanium.Android.FLAG_AUTO_CANCEL | Titanium.Android.FLAG_SHOW_LIGHTS
});
 
Ti.Android.NotificationManager.notify(2, notification);
 
var service = Ti.Android.currentService;
var serviceIntent = service.getIntent();
Ti.Android.stopService(serviceIntent);
// this will display that custom extra that we added when we created the intent
intent.putExtra('message', 'This is that little extra 1');
var teststring = serviceIntent.getStringExtra('message');
Ti.API.info('Extra!: ' + teststring);
 
//Ti.Android.stopService(serviceIntent);

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>