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