public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String title = intent.getStringExtra("title");
if(title==null)return;
Toast.makeText(context, title, Toast.LENGTH_LONG).show();
Log.e("ddddd", "onReceive: " + title);
// long id = intent.getLongExtra("id", 0);
//
// if (id != 0) {
// sendNotify(context, id);
// }
}
private void sendNotify(Context context, long id) {
ItemDAO itemDAO = new ItemDAO(context.getApplicationContext());
Item item = itemDAO.get(id);
File file = new File(FileUtil.getExternalStorageDir(FileUtil.APP_DIR),
"P" + item.getFileName() + ".jpg");
boolean isPicture = (item.getFileName() != null &&
item.getFileName().length() > 0 &&
file.exists());
NotificationManager nm = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
if (isPicture) {
Notification.Builder builder = new Notification.Builder(context);
builder.setSmallIcon(android.R.drawable.star_on)
.setWhen(System.currentTimeMillis())
.setContentTitle(context.getString(R.string.app_name));
Notification.BigPictureStyle bigPictureStyle =
new Notification.BigPictureStyle();
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
bigPictureStyle.bigPicture(bitmap)
.setSummaryText(item.getTitle());
builder.setStyle(bigPictureStyle);
// 發出通知
nm.notify((int)item.getId(), builder.build());
}
// 如果沒有儲存照片檔案
else {
// 建立NotificationCompat.Builder物件
NotificationCompat.Builder builder =
new NotificationCompat.Builder(context);
// 設定圖示、時間、內容標題和內容訊息
builder.setSmallIcon(android.R.drawable.star_big_on)
.setWhen(System.currentTimeMillis())
.setContentTitle(context.getString(R.string.app_name))
.setContentText(item.getTitle());
// 發出通知
nm.notify((int)item.getId(), builder.build());
}
}
}