I have written code which shows a notification when an SMS has been sent.
For some reason the code does not work on Android 7 like on all lower API levels.
The second parameter (contact) is lost and retrieved as null in the CompletedReceiver class.
Here is my code:
SendMessage method
private static void sendMessage(Context context, Message message, SystemContact contact) {
SmsManager smsManager = SmsManager.getDefault();
// Create sent intent.
Intent sentIntent = new Intent(context, SmsController.SendResultReceiver.class);
sentIntent.putExtra(context.getString(R.string.key_message_id), message.getId());
sentIntent.putExtra(context.getString(R.string.key_contact), contact);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, RequestCodes.SENT_SMS, sentIntent, PendingIntent.FLAG_UPDATE_CURRENT);
smsManager.sendTextMessage(contact.getPhoneNr(), null, message.getMsg(), pendingIntent, null);
}
CompletedReceiver
private void initPassedData(Context context, Intent intent) {
this.message = IntentHelper.getMessageById(context, intent);
this.contact = (SystemContact) intent.getSerializableExtra(context.getString(R.string.key_contact));
}
Also what does the PendingIntent.FLAG_UPDATE_CURRENT mean?