package com.ict.qinyuanminemonitor.tools;
import com.ict.qinyuanminemonitor.R;
import
com.ict.qinyuanminemonitor.SubSystemSelectActivity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Vibrator;
public class AlarmNotification {
private final int NOTIFICATION_ID = 0000;
private MediaPlayer mpMediaPlayer;
private Vibrator shake;
private Context context;
public AlarmNotification(Context context) {
super();
this.context = context;
this.mpMediaPlayer = MediaPlayer.create(context,
R.raw.classic_alarm);
this.shake = (Vibrator) context
.getSystemService(Service.VIBRATOR_SERVICE);
}
@SuppressWarnings("deprecation")
public void sendNotification(int icon, String str) {
Intent intent = new Intent(context,
SubSystemSelectActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pi = PendingIntent.getActivity(context, 0,
intent, 0);
// 创建一个Notification
Notification notify = new Notification();
// 为Notification设置图标。该图标显示在状态栏
notify.icon = icon;
// 为Notification设置发送时间
notify.when = System.currentTimeMillis();
// 设置声音
mpMediaPlayer.setLooping(false);
mpMediaPlayer.start();
// 设置默振动
long[] vibrate = new long[] {0,100,150,200};
shake.vibrate(vibrate, -1);
// 设置事件信息
notify.setLatestEventInfo(context, "警告!", str, pi);
// 获取系统的NotificationManager服务
NotificationManager notificationManager =
(NotificationManager) context
.getSystemService(context.NOTIFICATION_SERVICE);
// 发送通知
notificationManager.notify(NOTIFICATION_ID, notify);
}
public void stopNotification(){
mpMediaPlayer.stop();
shake.cancel();
}
}