2016-06-23 17:12:25 +02:00
|
|
|
package net.foucry.pilldroid;
|
|
|
|
|
|
|
|
import android.app.Notification;
|
|
|
|
import android.app.NotificationManager;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Vibrator;
|
2016-11-01 23:35:00 +01:00
|
|
|
import android.util.Log;
|
2016-06-23 17:12:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by jfoucry on 6/23/16.
|
|
|
|
*/
|
|
|
|
public class NotificationPublisher extends BroadcastReceiver {
|
|
|
|
|
2016-11-03 13:57:19 +01:00
|
|
|
private static String TAG = Thread.currentThread().getStackTrace()[1].getMethodName();
|
2016-06-23 17:12:25 +02:00
|
|
|
public static String NOTIFICATION_ID = "notification-id";
|
|
|
|
public static String NOTIFICATION = "notification";
|
|
|
|
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2016-11-03 13:57:19 +01:00
|
|
|
Log.i(TAG, "");
|
2016-11-01 23:35:00 +01:00
|
|
|
|
2016-06-23 17:12:25 +02:00
|
|
|
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
|
|
|
|
Notification notification = intent.getParcelableExtra(NOTIFICATION);
|
|
|
|
int id = intent.getIntExtra(NOTIFICATION_ID,0);
|
2017-12-11 15:27:46 +01:00
|
|
|
if (notificationManager != null) {
|
|
|
|
notificationManager.notify(id, notification);
|
|
|
|
}
|
2016-11-08 12:10:27 +01:00
|
|
|
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
2017-12-11 15:27:46 +01:00
|
|
|
if (vibrator != null) {
|
|
|
|
vibrator.vibrate(400);
|
|
|
|
}
|
2016-06-23 17:12:25 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|