私のアプリケーションは、getResources() または getApplicationContext() のメソッドを作成するように求めています。
これらのメソッドは、BroadcastReceiver で呼び出すことはできませんか?
@Override
public void onReceive(Context context, Intent arg1) {
createNotification(Calendar.getInstance().getTimeInMillis());
}
public void createNotification(long when) {
Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(),
R.drawable.stamptwo);
int smalIcon = R.drawable.stamptwoxhdpi;
Intent intent = new Intent(context.getApplicationContext(),
Lockscreen.class);
intent.putExtra(NOTIFICATION_DATA, notificationData);
intent.setData(Uri.parse("content://" + when));
PendingIntent pendingIntent = PendingIntent.getActivity(
context.getApplicationContext(), 0, intent,
Intent.FLAG_ACTIVITY_NEW_TASK);
NotificationManager notificationManager = (NotificationManager) context
.getApplicationContext().getSystemService(
Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
context.getApplicationContext())
.setWhen(when)
.setContentText(notificationContent)
.setContentTitle(notificationTitle)
.setSmallIcon(smalIcon)
.setAutoCancel(true)
.setTicker(notificationTitle)
.setLargeIcon(largeIcon)
.setDefaults(
Notification.DEFAULT_LIGHTS
| Notification.DEFAULT_VIBRATE
| Notification.DEFAULT_SOUND)
.setContentIntent(pendingIntent);
Notification notification = notificationBuilder.build();
notificationManager.notify((int) when, notification);
}
}