Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android 12(S) からは PendingIntentを作る際に FLAG_IMMUTABLE or FLAG_MUTABLE の指定が必要になる #151

Closed
tateisu opened this issue Feb 25, 2021 · 3 comments

Comments

@tateisu
Copy link
Owner

tateisu commented Feb 25, 2021

Android Sの制限がもう一つあった。
android.app.PendingIntent.getActivity(PendingIntent.java:401)

java.lang.IllegalArgumentException:
{pkgName}: Targeting S+ (version 10000 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.

@tateisu
Copy link
Owner Author

tateisu commented Feb 25, 2021

FLAG_IMMUTABLE
Added in API level 23
Flag indicating that the created PendingIntent should be immutable. This means that the additional intent argument passed to the send methods to fill in unpopulated properties of this intent will be ignored.

FLAG_IMMUTABLE only limits the ability to alter the semantics of the intent that is sent by send() by the invoker of send(). The creator of the PendingIntent can always update the PendingIntent itself via FLAG_UPDATE_CURRENT.

作成されたPendingIntentが不変であることを示すフラグ。 これは、このインテントの未入力のプロパティを入力するためにsendメソッドに渡される追加のインテント引数が無視されることを意味します。
FLAG_IMMUTABLEは、send()の呼び出し元によってsend()によって送信されるインテントのセマンティクスを変更する機能のみを制限します。 保留中のインテントの作成者は、FLAG_UPDATE_CURRENTを介して保留中のインテント自体をいつでも更新できます。


FLAG_MUTABLE
Added in Android S
Flag indicating that the created PendingIntent should be mutable. This flag cannot be combined with FLAG_IMMUTABLE.

Up until Build.VERSION_CODES.R, PendingIntents are assumed to be mutable by default, unless FLAG_IMMUTABLE is set. Starting with Build.VERSION_CODES.S, it will be required to explicitly specify the mutability of PendingIntents on creation with either (@link #FLAG_IMMUTABLE} or FLAG_MUTABLE. It is strongly recommended to use FLAG_IMMUTABLE when creating a PendingIntent. FLAG_MUTABLE should only be used when some functionality relies on modifying the underlying intent, e.g. any PendingIntent that needs to be used with inline reply or bubbles.
作成されたPendingIntentが変更可能であることを示すフラグ。 このフラグをFLAG_IMMUTABLEと組み合わせることはできません。

Build.VERSION_CODES.Rまでは、FLAG_IMMUTABLEが設定されていない限り、PendingIntentsはデフォルトで変更可能であると見なされていました。 Build.VERSION_CODES.S以降、作成時にPendingIntentsの可変性を(@link #FLAG_IMMUTABLE}またはFLAG_MUTABLEのいずれかで明示的に指定する必要があります。PendingIntentを作成するときはFLAG_IMMUTABLEを使用することを強くお勧めします。FLAG_MUTABLEは、次の場合にのみ使用してください。 一部の機能は、基になるインテントの変更に依存しています。たとえば、インライン応答またはバブルで使用する必要があるPendingIntentなどです。

@tateisu
Copy link
Owner Author

tateisu commented Feb 25, 2021

SubwayTooter の場合

  • PendingIntent は通知タップと削除に使ってるだけ
  • PendingIntent.send() をアプリ内部から呼び出す箇所はない。
  • PendingIntent に指定するIntentは全ての情報をIntent.data のURIに持たせている

よって PendingIntent を作成している部分全てにFLAG_IMMUTABLEを追加するだけで良さそう

@tateisu tateisu changed the title : Targeting S+ (version 10000 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. Android 12(S) からは PendingIntentを作る際に FLAG_IMMUTABLE or FLAG_MUTABLE の指定が必要になる Feb 25, 2021
@tateisu
Copy link
Owner Author

tateisu commented Nov 6, 2021

一通り追加してるぽい。一旦クローズ

@tateisu tateisu closed this as completed Nov 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant