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
   |  
public void onReceive(Context context, Intent intent)
		{
			Toast.makeText(context, intent.getStringExtra("hello"), Toast.LENGTH_SHORT).show();
 
			NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
 
			NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
			Notification notif = builder
					.setSmallIcon(R.drawable.james)
					.setContentText("ça marche a la merveille")
					.setContentTitle("boulbi 92i")
					.setWhen(System.currentTimeMillis()).build();
			notif.flags = Notification.FLAG_AUTO_CANCEL;
 
			manager.notify(0, notif);
 
		}
 Button start = (Button)findViewById(R.id.button1);
        start.setOnClickListener(new OnClickListener()
        {
 
			@Override
			public void onClick(View arg0)
			{
				if(!test)
				{
					Intent hello = new Intent("ACTION_HELLO");
					hello.putExtra("hello", "Bonjour tout le monde");
 
					AlarmManager alarm = (AlarmManager)getSystemService(ALARM_SERVICE);
					PendingIntent pending = PendingIntent.getBroadcast(MainActivity.this, 0, hello, 0);
 
					//Calendar call = Calendar.getInstance();
					//call.set(Calendar.SECOND, 20);
 
					alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 5000, pending);
				}
				else
					Toast.makeText(MainActivity.this, "Le service est deja en cours", Toast.LENGTH_SHORT).show();
 
				test = true;
			}
 
        }); | 
Partager