dahlbyk
dahlbyk

Reputation: 77570

How to troubleshoot Android intent filters?

As illustrated by a number of questions here, it's sometimes difficult to get intent filters configured correctly. If a filter is not working like expected (e.g., app shows "permission denied"), what are some tricks to figure out why?

Update: To clarify, I'm not just talking about built-in intents. It's been a struggle getting a custom OAuth callback URL to resolve to the correct activity, but I can't tell if the issue is due to my intent filter or something else.

Upvotes: 3

Views: 1112

Answers (3)

tendays
tendays

Reputation: 291

Option 1: Catch-all IntentFilter, then debug IntentFilter.match()

I wanted to ask exactly the same question. I know of no readily available tools for debugging failing intent filters but this is the approach I'm thinking of:

  1. Make the intent filter as permissive as possible (i.e. put wildcards everywhere you can) so that you can grab and examine the Intent from within your application

  2. Submit the Intent object thus obtained to your real intent filter's match method. You should be able to tell at which stage matching failed by looking which NO_MATCH_* constant is returned.

Once you captured the Intent you can also run the matching in a debugger so better understand what is wrong.

Option 2: Use the App Links Assistant

(This option only works if you want to debug http/https links)

  1. Make sure the App Links Assistant plugin is enabled (File > Settings > Plugins > check "App Links Assistant" in the list). Restart Studio if prompted
  2. Open the assistant (Tools > App Links Assistant)
  3. Click "Open URL Mapping Editor" button in the side bar
  4. Create/Edit your IntentFilter in the dialog
  5. Type a test url in the "Check URL Mapping" box.

This will not tell you why a filter does not work, but allows much faster trial-and-error testing. That's what allowed me to understand why my filter wouldn't work (turns out we can't put wildcards in the "port". I set scheme to http, host filter to *, left port number empty (tried * as well) and set a pathPattern, but it would only matcĥ port 80 (on arbitrary hosts)

Upvotes: 4

jtt
jtt

Reputation: 13541

Some intent-filters are protected by the system. And as such would require you to have a permission before you can use it. The trick is to know what you want. Once you know what you want, then you can look up intent filters that are available.

The preferred option would be to learn the traverse the android source code and find what you're looking for in the manifest.

Upvotes: 0

Gangnus
Gangnus

Reputation: 24474

First - check if called component is declared in the parent manifest for the calling component.

If the called component is yours and not in the same app, check if it is declared in its own manifest.

Other possible problem - if the called component is correct by itself (broken layouts, forbidden elements in a widget)

Upvotes: 0

Related Questions