Pilldroid/app/src/main/java/net/foucry/pilldroid/NotificationPublisher.java
Jacques Foucry 9c7945406f Remove GooglePlay references
Add some tests to avoid nullPointerException
2017-12-11 15:27:46 +01:00

36 lines
1.2 KiB
Java

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;
import android.util.Log;
/**
* Created by jfoucry on 6/23/16.
*/
public class NotificationPublisher extends BroadcastReceiver {
private static String TAG = Thread.currentThread().getStackTrace()[1].getMethodName();
public static String NOTIFICATION_ID = "notification-id";
public static String NOTIFICATION = "notification";
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "");
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = intent.getParcelableExtra(NOTIFICATION);
int id = intent.getIntExtra(NOTIFICATION_ID,0);
if (notificationManager != null) {
notificationManager.notify(id, notification);
}
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator != null) {
vibrator.vibrate(400);
}
}
}