How to troubleshoot Android intent filters? - android

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.

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:
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
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)
Make sure the App Links Assistant plugin is enabled (File > Settings > Plugins > check "App Links Assistant" in the list). Restart Studio if prompted
Open the assistant (Tools > App Links Assistant)
Click "Open URL Mapping Editor" button in the side bar
Create/Edit your IntentFilter in the dialog
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)

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)

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.

Related

Android 10 perform intent to settings live captioning

I would like to make a Intent to send the user to the settings screen which it has the switch to enable the Live Captioning introduced by Android 10, is there any way to to this intent?
The manual way is as described in this post
I've tried this intent:
startActivity(Intent(ACTION_CAPTIONING_SETTINGS));
But it redirects to general captions activation
The only intent i found was working is
startActivity(Intent("com.android.settings.action.live_caption"))
(category DEFAULT if you want to pass that as well)
I found this by finding the top activity when I had it open on my phone with adb and then inspecting the settings application to find intents matching the activity name.
Be aware, this is not an offical way to open this dialog. It may be subject to change and is very likely to differ between devices.
I could not find an Intent which is more general, so I'm assuming there's no offical way to open the activity.

Android: intent started, but which parameters to pass?

I want to add support for several navigation applications in my app. I know how to start another activity as intent and pass parameters - but is there any way to check the naming of the parameters I should pass? For example: Navigon should start with routing calculation and instructions immediately after starting from within my application. So far, I'm not even sure Navigon supports parameter passing, but I don't even know how to figure that out.
Thanks in advance!
You should check the documentation for each app you're interested in supporting. They should have it laid out somewhere. If they don't, they might not support explicit intent extras.
For example, Navigon has their options laid out here(found by searching "android navigon intent"):
http://www.navigon.com/portal/common/faq/files/online_documents/NAVIGON_Android_public_Intent.pdf

How to configure the android intent actions in android manifest

I have a webview in my app, on trying to do actions like making a call (Tapping call button from results displayed in webview), sending mails and other actions, my webview doesn't perform those actions
I Found a solution to add the intent actions in my web view activity as
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
startActivity(intent)
Instead of doing so is there any way to add in the android manifest file
or Is there any way to turn on all of the intent actions for the webview so that
there wont be further issues in handling the actions
Can someone help me on this pls
Your answer seems to me a bit strange, I think you are a bit confuse about the difference between Intent and manifest permission. The first one are the system used by android to let app communicate with each other, the second one allow you to use some feature of the device like wifi and direct phone call that need the explicit agreement of the user to be used (the prompt that popup when you make the first install of an app).
With this clarification it is clear that if you want to do something that require another app you will have to make an Intent. This Intent, if well formed, will be elaborated by the os that will take care of sending it to the correct application able to accomplish the Intentrequirement.
So the answer to your question, as far as i know, is no, you have to use intent if you have the need of calling external app. It's also a good practice to set in the manifest only the permission really needed by the app, this way the user know what the app really can do and and what it can't do.
Hope i understand your question and answer it.

How to lauch android's apps preferences (from Contacts, Messages, ...)

I've been searching and I couldn't find a topic that could clarify me 100%.
My question is: How can I launch an android's app preferences activity (from Contacts, Messages, ...) on my own app?
I give an example:
Imagine I'm developing an app which allows the user to quickly access to Message's Settings. I don't need to send or receive any information, I only need to open the activity, create a shortcut for it.
Someone knows if this can be done and even opening specific locations of the apps?
You don't need to know any specific locations or specific apps for these actions, simply look into Intent.ACTION_PICK.
Picking a Contact: get contact info from android contact picker
Picking a picture: How to pick an image from gallery (SD Card) for my app?
The best answer in this thread has the solution:
android: how do i open another app from my app?
Also check:
http://android-developers.blogspot.com/2009/01/can-i-use-this-intent.html
To open settings, you can try:
startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS, 0));
There is no difference in writing in code an Explicit Intent which will go to a specific activity of your app and using the same format to go to a specific activity some other app. A few things to be aware of: (1) The receiving activity may be expecting particular data and fail otherwise. (2) The standard apps you are considering like Contacts, Messages while you can find the source for them in the Android Open Source Project (AOSP) may be changed by the manufacturers so that the activity names and necessary extra data could be different.
In order to maintain as much compatibility between all of the different Android manufacturers, you should stick to the standard implicit intent with the appropriate action/data.

Intent resolution in Android

If I want to create custom address book (which overrides my phone's default address book), and if I want it to be used by all applications, what should be my intent-filter? Does Android allow me to do such a thing considering the fact that such a third-party app could potentially be malicious?!
And, if I want to have yet another address book application, I suppose the second app also has same intent-filter, isn't it? How does the framework decide which app to pick if I click on Contacts button when making a call? In other words, how does the framework resolve intents in case,there is a conflict between multiple intent-filters?
You can replace any application on Android platform, even Home. Android documentation explains everything there is to know about Intents and Intent Filters and there is a section called Intent Resolution that answers your question. Intent Resolution section for Intent class has some additional information.
As far as I can tell Android doesn't try to resolve a conflict. It ask the user which application to run and gives them the choice to mark this Activity as the default for this Intent. They give an example about mail app here.
While Mr. Smiljanić is basically correct, there is no Contacts application in Android for you to replace. There is Dialtacts, which is the application supporting the contacts, call log, and dialer. That application cannot be replaced, mostly because the dialer cannot be replaced.
So, while you may be able to override some intent filters and get control on some contacts-related requests, you will be unable to get the contacts portion of Dialtacts overridden, which will confuse users.

Categories

Resources