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
|
...
public class MyAlarmService extends Service {
NotificationManager nm;
public void onCreate(Bundle savedInstanceState) {
Toast myToast = Toast.makeText(this, "blabla", Toast.LENGTH_LONG);
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
myToast.show();
//vibre pendant 1 seconde, puis attend 1/2 secondes avant de recommencer (3 fois en tout).
vibrator.vibrate(new long[]{0,1000,500,1000,500,1000}, -1);
}
public IBinder onBind(Intent intent) {
Toast.makeText(this, "MyAlarmService.onBind()", Toast.LENGTH_LONG).show();
return null;
}
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "MyAlarmService.onDestroy()", Toast.LENGTH_LONG).show();
}
public int onStartCommand(Intent intent, int flags, int startId) {
Bundle bundle = intent.getExtras();
long messageid = bundle.getLong("passID", 0);
int messageee = (int) messageid;
String message = TaskReminder.getTaskTitle(MyAlarmService.this, messageid);
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
final NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notification et le texte qui apparait à la création de la notfication
final Notification notification = new Notification(R.drawable.notification, "SaS reminder notification", System.currentTimeMillis());
Bundle objetbunble = new Bundle();
objetbunble.putLong("passID", messageid);
Intent myIntent = new Intent(this, ViewTaskReminder.class);
myIntent.putExtras(objetbunble);
final PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, myIntent, 0);
final String notificationTitle = "Reminder BIS";
final String notificationDesc = "This is a reminder from Spot&share reminder !";
notification.setLatestEventInfo(this, notificationTitle, notificationDesc, pendingIntent);
notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(messageee, notification);
Uri notificationring = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notificationring);
r.play();
vibrator.vibrate(new long[]{0,1000,500,1000,500,1000}, -1);
return super.onStartCommand(intent, flags, startId);
}
....
} |
Partager