I have a certain intent (NDEF_DISCOVERED
), some of which I cannot handle correctly, so I want to redirect those to android's default nfc handler.
So i take the intent, setComponent(null)
, and then startActivity(intent)
But.. it always comes back to my app in an infinite loop of intent throwing.
Is there a way I can send off an intent to anyone but my app? Or send it to android's default nfc handler?
EDIT: So I used vikram's answer to query the packagemanager for possible activities to handle my intent, then looped thru and found the activity with the highest priority (who isn't me) and sent an explicit intent to them.
there is also another option than to do a own chooser here ( different looking chooser might confuse the user )
I am using it - and it works fine - just do not like this magic constant 250 - but do not yet see another way.
A custom chooser dialog/popup will be better for you in this case. Instead of launching an intent, use the
PackageManager
toqueryIntentActivities(Intent, int)
. From theList<ResolveInfo>
thatqueryIntentActivities(Intent, int)
returns, filter out your own app using thepackageName
:Edit 1:
The following code will create and show a
PopupWindow
whenevershowList()
is called. The xml layout file used to returnpopupView
contains nothing but aLinearLayout
(R.layout.some_popup_view):This code is just a simple demonstration. For it to be anything close to usable, you will probably need to add a
ListView
with a custom adapter to thisPopupWindow
. In theOnClickListener
for theListView
, you will retrieve the package name of the Application that the user clicks on, and generate an intent to start that activity. As of now, the code only displays how to filter out your own application using a custom chooser. In theif
block, replace"com.example.my.package.name"
with your app's package name.