私が作成したParcelable Java Object
のフィールドを表示するには、ある時間に警告を出そうとしています。私は以前これに関連する質問があることを知っていますが、私はこの問題の解決策を見いだせませんでした。 Receiver
は、データが渡されないと正常にアラートを作成しますが、を作成するFragment
のIntent
から送信するデータは保持されません。データがbroadcastReceiverに送信されていません
Receiver
のための私のコードは以下の通りです:
public class NotificationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
IUser eu = intent.getExtras().getParcelable("USER");
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent repeating_intent = new Intent(new Intent(context, MainActivity.class));
repeating_intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 100, repeating_intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentIntent(pendingIntent)
.setSmallIcon(android.R.drawable.arrow_up_float)
.setContentTitle("Warning: Approaching Threshold")
.setContentText(eu.get_forecast_info().get_estimate_cur_cycle_total_cost()+" is the price")
.setAutoCancel(true);
notificationManager.notify(100, builder.build());
}
}
Receiver
ためIntent
を供給するためのコードは以下の通りです:アンドロイドの最新バージョンで
trigger_b = (Button) view.findViewById(R.id.trigger_button);
trigger_b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 10);
calendar.set(Calendar.MINUTE, 14);
calendar.set(Calendar.SECOND, 0);
Intent intent = new Intent(getActivity().getApplicationContext(), NotificationReceiver.class);
Bundle c = new Bundle();
c.putParcelable("USER", eu);
intent.putExtras(c);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getActivity().getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
}
});
あなたがテストしているAndroidのバージョンは何ですか? –
私はバージョン25を使用しています! – James