IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Comparer la date système au DatePicker et notifier l'utilisateur


Sujet :

Android

  1. #1
    Membre à l'essai
    Homme Profil pro
    Développeur en systèmes embarqués
    Inscrit en
    Février 2012
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2012
    Messages : 19
    Points : 11
    Points
    11
    Par défaut Comparer la date système au DatePicker et notifier l'utilisateur
    bonsoir,
    je vien de developer une application qui permet a l'utulisateur apres le remplisage de DatePicker et timePicker on lui affiche une notification j'ai progarmer mon fichier service
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    public class StatusBarService extends Service {
     
    	private Timer _timer = null;
     
    	@Override
    	public IBinder onBind(Intent arg0) {
    		// TODO Auto-generated method stub
    		return null;
    	}
     
    	@Override
    	public void onCreate() {
    		super.onCreate();		
    	}
     
    	@Override
    	public void onDestroy() {
    		super.onDestroy();
    	}
     
    	@Override
    	public int onStartCommand(Intent intent, int flags, int startId) {
     
            _timer = new Timer();
            _timer.schedule(new TimerTask() {
                @Override
                public void run() {
                	// Message message = new Message();
                	Bundle bundle = new Bundle();
                	bundle.putString("message_title", "Status bar notification");
                	bundle.putString("message_text", "Click here to fire intent");
                	bundle.putString("ticker_text", "Notification");
                	/*
                	message.obj = bundle;
                	toastHandler.sendMessage(message);
                	*/
     
                	/* Handler required only for toast notifications */
     
                	// Get reference to notification manager
                	NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
     
                	// Instantiate the notification
                	Notification notification = new Notification(
                			R.drawable.icon,			// The resource id of the icon to put in the status bar.
                			bundle.getString("ticker_text"), 	// The text that flows by in the status bar when the notification first activates.
                			System.currentTimeMillis());		// The time to show in the time field. In the System.currentTimeMillis timebase.
                	notification.flags = Notification.FLAG_AUTO_CANCEL;
     
                	// Set the expanded message and the intent to fire when the user clicks the expanded message
                	Intent notificationIntent = new Intent(
                			getApplicationContext(), 		// Application context.
                			StatusBarNotifications.class);		// Activity to open.
                	PendingIntent contentIntent = PendingIntent.getActivity(
                			getApplicationContext(), 0, notificationIntent, 0);
                	notification.setLatestEventInfo(
                			getApplicationContext(), 
                			bundle.getString("message_title"), 
                			bundle.getString("message_text"), 
                			contentIntent);
     
                	// Pass notification to notification manager
                	notificationManager.notify(
                			1, 		// Unique ID of notification  
                			notification); 	// Notification
     
     
                }
            }, 5000);
     
            _timer = new Timer();
            _timer.schedule(new TimerTask() {
                @Override
                public void run() {
                	// Message message = new Message();
                	Bundle bundle = new Bundle();
                	bundle.putString("message_title", "Sasdasan");
                	bundle.putString("message_text", "Csdasdasent");
                	bundle.putString("ticker_text", "Nasdasion");
                	/*
                	message.obj = bundle;
                	toastHandler.sendMessage(message);
                	*/
     
                	/* Handler required only for toast notifications */
     
                	// Get reference to notification manager
                	NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
     
                	// Instantiate the notification
                	Notification notification = new Notification(
                			R.drawable.icon,			// The resource id of the icon to put in the status bar.
                			bundle.getString("ticker_text"), 	// The text that flows by in the status bar when the notification first activates.
                			System.currentTimeMillis());		// The time to show in the time field. In the System.currentTimeMillis timebase.
                	notification.flags = Notification.FLAG_AUTO_CANCEL;
     
                	// Set the expanded message and the intent to fire when the user clicks the expanded message
                	Intent notificationIntent = new Intent(
                			getApplicationContext(), 		// Application context.
                			StatusBarNotifications.class);		// Activity to open.
                	PendingIntent contentIntent = PendingIntent.getActivity(
                			getApplicationContext(), 0, notificationIntent, 0);
                	notification.setLatestEventInfo(
                			getApplicationContext(), 
                			bundle.getString("message_title"), 
                			bundle.getString("message_text"), 
                			contentIntent);
     
                	// Pass notification to notification manager
                	notificationManager.notify(
                			1, 		// Unique ID of notification  
                			notification); 	// Notification
     
     
                }
            }, 5000);
     
    		return super.onStartCommand(intent, flags, startId);
    	}
    et j'ai programer mon classe main
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    public class StatusBarNotifications extends Activity {
        /** Called when the activity is first created. */
    	TimePicker timePicker;
    	DatePicker datePicker;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
     
            // Start service
            Button btnOpen = (Button) findViewById(R.id.btnSetAlarm);
            btnOpen.setOnClickListener(new OnClickListener() {
     
    			@Override
    			public void onClick(View v) {
    				// TODO Auto-generated method stub
    				  timePicker = (TimePicker) findViewById(R.id.timePicker);
    	                datePicker = (DatePicker) findViewById(R.id.datePicker);
    	                //---use the AlarmManager to trigger an alarm---
    	                AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);                 
     
    	                //---get current date and time---
    	                Calendar calendar = Calendar.getInstance();       
     
    	                //---sets the time for the alarm to trigger---
    	                calendar.set(Calendar.YEAR, datePicker.getYear());
    	                calendar.set(Calendar.MONTH, datePicker.getMonth());
    	                calendar.set(Calendar.DAY_OF_MONTH, datePicker.getDayOfMonth());                 
    	                calendar.set(Calendar.HOUR_OF_DAY, timePicker.getCurrentHour());
    	                calendar.set(Calendar.MINUTE, timePicker.getCurrentMinute());
    	                calendar.set(Calendar.SECOND, 0);
    	                Intent i = new Intent(getApplicationContext(), StatusBarService.class);
    	        		getApplicationContext().startService(i);
    			}
    		});
        }
    }
    le problème c'est que j'arrive pas savoir le code qui permet de comparer la date saisie par l’utilisateur et la date System pour lancer une notification...
    merci d'avance pour votre aide

  2. #2
    Expert éminent

    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    4 253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2007
    Messages : 4 253
    Points : 7 618
    Points
    7 618
    Billets dans le blog
    3
    Par défaut
    La date systeme:

    En long (milliseconds): System.currentTimeMillis()
    En "Date": new Date();
    En "Calendar": Calendar.getInstance();

    Comparaison de Dates:
    d1.before(d2) ou d1.after(d2)

    Comparaison de longs:
    l1 < l2 ou l1 > l2

    Calendar => Date : calendar.getTime();
    Date => Calendar: Calendar calendar = Calendar.getInstance(); calendar.setTime(d);

    Date => long: date.getTime();
    long => Date: new Date(l);

Discussions similaires

  1. Comparer 2 dates de datepicker
    Par tremeur53 dans le forum Langage
    Réponses: 2
    Dernier message: 16/12/2013, 22h41
  2. [UI] Comparer 2 dates Datepicker
    Par almoha dans le forum jQuery
    Réponses: 2
    Dernier message: 02/12/2012, 21h01
  3. [DB2] - Comparer une date à la date système
    Par rémi_tounul dans le forum DB2
    Réponses: 3
    Dernier message: 19/05/2005, 11h45
  4. comment comparer deux dates?
    Par billoum dans le forum C++Builder
    Réponses: 2
    Dernier message: 21/08/2004, 21h08
  5. [Sybase] Récupération de la date système
    Par atos dans le forum Sybase
    Réponses: 2
    Dernier message: 03/03/2004, 14h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo