Прежде всего я пробовал все ответы, упомянутые в переполнении стека, но никто не работал с моим приложением, я знаю, что это просто, но я не могу понять, почему это не так. за работой. , поэтому я увидел, чтобы поделиться с вами своим кодом, чтобы помочь мне в этом. Я бегу на API 22
.Передача текста уведомления и изображения в другое действие при событии click
это activity
, которые содержат textView
для получения текста извещения.
public class EventDetails extends AppCompatActivity {
public static TextView txtDet;
public String strdet;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
onNewIntent(getIntent());
setContentView(R.layout.activity_event_details);
txtDet = (TextView) findViewById(R.id.txtDetail);
Intent MyIntent = getIntent();
strdet = MyIntent.getStringExtra("txtDetails");
txtDet.setText(strdet);
}
я использовал getStringExtra
передать текст при нажатии на календарную дату, и она работает хорошо, поэтому я хочу, чтобы использовать тот же textView
для получения текста уведомления, я не имею проблему с помощью другого textView
, и в в то же время я хочу получить отдельный image
для каждого уведомления.
и это уведомление activity
, я назвал AlertReceiver
public class AlertReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
int notificationId = intent.getIntExtra("id", -1);
switch(notificationId){
case 1:
createNotification(context, "title1", "event1", "event of today");
break;
case 2:
createNotification(context, "title2", "event2", "event of today");
break;
case 3:
createNotification(context, "title3", "event3", "event of today");
break;
case 4:
createNotification(context, "title4", "event4", "event of today");
break;
}
}
public void createNotification(Context context, String msg, String msgText,String msgAlert){
PendingIntent notificIntent = PendingIntent.getActivity(context, 0, new Intent(context, EventDetails.class), 0);
NotificationCompat.Builder mBuilder=new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.not)
.setContentTitle(msg)
.setTicker(msgAlert)
.setContentText(msgText);
//intent to fire when notification clicked on
mBuilder.setContentIntent(notificIntent);
//how the person will be notified
mBuilder.setDefaults(NotificationCompat.DEFAULT_SOUND);
//cancel notification when clicked in the taskbar
mBuilder.setAutoCancel(true);
NotificationManager mNotificationManager= (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
}
}
любые предложения?
ДА, это решить мою проблему, спасибо много, даже я теперь понял, как именно намерение работает, но я только что отредактировали putStringExtra к putExtra – zyz82
насчет образа? я имею в виду .setSmallIcon (R.drawable.not) – zyz82