androidandroid-intentnfcandroid-pendingintentandroid-intent-chooser

how to disable chooser dialog in android?


I am making an app with using NFC.

Whenever the tag is detected, chooser dialog keeps pop up with Complete action using title and possible apps.

I covered it up with using SingleTop or SingleTask. However, It does not work all the time.

It seems like I can't really touch the things that happen after NFC tag has been detected because it works on a system level. Not only in my app. It pops up everywhere.

I've found some ways that I can customise the chooser dialog, However, Not for NFC because In my app, I never implemented anything about createChooser().

I tried adding something more code for chooser like this

val intent = Intent(this, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
// start
val list = arrayListOf<String>()
list.add("me@example.com")
intent.putExtra(Intent.EXTRA_EMAIL, list)
intent.putExtra(Intent.EXTRA_SUBJECT, "Hi")
intent.putExtra(Intent.EXTRA_TEXT, "Hi,This is Test")
pendingIntent = PendingIntent.getActivity(this, 0, Intent.createChooser(intent, "Yaho"), 0)

And I get the same result. I guess the reason why it is is it is controlled in a system level.

The best solution is avoiding the detection of NFC tag in some specific activities or fragments & control that chooser dialog.


Solution

  • Using ForgroundDispatch solves the problem.