summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2021-11-15 11:46:29 +0100
committerIvan Solovev <ivan.solovev@qt.io>2021-12-08 09:52:21 +0100
commit3ec991f35e0e7450c9fdc64abea4e502f44605c4 (patch)
tree625305c3b831c52180bed48686b0c81f4cb778e4
parentda3720879160d78c4655ab298da48d4f7f760020 (diff)
downloadqtconnectivity-3ec991f35e0e7450c9fdc64abea4e502f44605c4.tar.gz
NFC: Fix PendingIntent creation for Android 12
Since Android 12 it's mandatory to specify the mutability of each pending intent. In NFC we require a mutable intent, so we need to conditionally use FLAG_MUTABLE. This was a default value for an intent before Android 12, so no adjustment is required for earlier versions. Fixes: QTBUG-98073 Change-Id: I9a478db016bf9646d84d6e458647614785005977 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit 3753c53fc810c292db93fcfbafffbc097afb0ed1)
-rw-r--r--src/android/nfc/src/org/qtproject/qt5/android/nfc/QtNfc.java8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/android/nfc/src/org/qtproject/qt5/android/nfc/QtNfc.java b/src/android/nfc/src/org/qtproject/qt5/android/nfc/QtNfc.java
index 953ce08b..49bc8487 100644
--- a/src/android/nfc/src/org/qtproject/qt5/android/nfc/QtNfc.java
+++ b/src/android/nfc/src/org/qtproject/qt5/android/nfc/QtNfc.java
@@ -52,6 +52,7 @@ import android.content.IntentFilter;
import android.nfc.NfcAdapter;
import android.content.IntentFilter.MalformedMimeTypeException;
import android.os.Bundle;
+import android.os.Build;
import android.util.Log;
import android.content.BroadcastReceiver;
import android.content.pm.PackageManager;
@@ -82,11 +83,16 @@ public class QtNfc
return;
}
+ // Since Android 12 (API level 31) it's mandatory to specify mutability
+ // of PendingIntent. We need a mutable intent, which was a default
+ // option earlier.
+ int flags = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) ? PendingIntent.FLAG_MUTABLE
+ : 0;
m_pendingIntent = PendingIntent.getActivity(
m_activity,
0,
new Intent(m_activity, m_activity.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),
- 0);
+ flags);
//Log.d(TAG, "Pending intent:" + m_pendingIntent);