Intent Filter on Android - android

I am reading the intent filter of the android, and having a few question need to ask.
Do they match the filter within the same application or all of the applications?
The scheme within the data tag, I have looked on the documentation on the android sdk website but no idea what it mean. It say scheme://host:port/path or pathPrefix or pathPattern
What is the host port and path .... What does the path relate to?

1) Depends on the type of intent that was requested. See implicit vs explicit intents in the "Intent resolution" section of the docs:
http://developer.android.com/guide/topics/intents/intents-filters.html
If you name the component exactly then you know which activity will launch. Other intents name a generic action and can be matched by multiple activities. The user gets a menu asking which app they want to use to complete the action normally. For instance download the Firefox app from the Marketplace and click on a link in an email, you'll get a prompt asking if you want to use the Browser or Firefox to open the URL.
2) That's for intercepting a custom URL scheme or overlaying HTTP requests. Sounds like that not something you're interested in doing, you can safely ignore it unless you need to use it. If you do want more info about it there's a question with some good answers already:
Launch custom android application from android browser

1) see #mikerowehl answer
2) data is referenced through Uniform Resource Indentifiers (URI's). In Android, scheme could be http, tel, file, content (don't know about others) and by specifying a certain scheme in a filter you're saying that your component can handle data provided that way.
host+port=authority. In case of a data whose scheme is http, host will of course be something like stackoverflow.com, port will probably be left unspecified (if you're accessing a proxy it could be 8080). In case of a content provider, the authority is by convention "the fully-qualified class name of the content provider (made lowercase)", without a port.
This should be the general idea. Documentation in this field is pretty scattered but you should be able to find information on a particular task (say opening email attachments) when you'll need.

Related

Android specific MIME type list?

I have been asked to add a "share" method to one of my Android applications which allows users to share by 1) Facebook 2) SMS and 3) Email
While researching, I have found that to allow users to select from "messaging" applications, I need to create the following Intent:
Intent messageIntent = new Intent(Intent.ACTION_SEND);
messageIntent.putExtra(Intent.EXTRA_SUBJECT, title);
messageIntent.putExtra(Intent.EXTRA_TEXT, content);
messageIntent.setType("vnd.android-dir/mms-sms");
// title and content set elsewhere...
This kind of works, although I am also given email clients in my list...
My Questions:
Is there a list somewhere of the Android specific MIME types that are available for us to use? The "vnd.android-dir/mms-sms" seemed pulled out of thin air to me from the example I found.
Is there the proper way to get ONLY messaging clients (ie. not mail clients) - or is that pretty much impossible to do in Android.
Disclaimer: The above code snippet was found from another SO post. Perhaps it is just me failing at Google - but I cannot seem to find any documentation on the legit Android developer site which listed out that this was the correct way to do this, or what my options are.
I have been asked to add a "share" method to one of my Android applications which allows users to share by 1) Facebook 2) SMS and 3) Email
Please allow the users to share how the users want, which may or may not be via those means.
I have found that to allow users to select from "messaging" applications, I need to create the following Intent
No, that allows users to share via any application that happens to support that undocumented and unsupported MIME type. Not every "messaging" application will necessarily support that MIME type, and applications that are not "messaging" applications are welcome to support that MIME type.
Is there a list somewhere of the Android specific MIME types that are available for us to use?
Not really, as generally they are undocumented or under-documented (e.g., the constant shows up somewhere without explanation).
The "vnd.android-dir/mms-sms" seemed pulled out of thin air to me from the example I found.
It probably came from the Android source code.
Is there the proper way to get ONLY messaging clients (ie. not mail clients) - or is that pretty much impossible to do in Android.
There are ~7 billion people on the planet. Each of them is welcome to have a different idea of what a "messaging client" is, what a "mail client" is, etc. Those are descriptive marketing terms, not technical definitions.
ACTION_SEND is for sharing content via MIME type. Any application can offer to support ACTION_SEND for any given MIME type, as the developers of any application can write what they want. Whether any given application is a "messaging client", "mail client", or something else is up to the end user. You have no means of reading the minds of users, nor do you have any legal means to prevent other programmers from writing what they want.
Now, there are various script-kiddie hacks for limiting the share list to certain apps, by application ID (a.k.a., package name). However, while there is only one Facebook (though I seem to recall they have a few apps), there are many SMS and email apps, and it would be difficult, if not impossible, for you to come up with a list of all of them, let alone maintain that list over time.
My strong recommendation is to format your content usefully, and allow the users to share that content using the apps that they wish.

How would you implement routing within an Activity for AppLinks?

So the applinks documentation states that you should specify your app's package name through the al:android:package property, and the consuming application should launch an Intent to start your app. What I feel is lacking from the documentation is a suggestion or specification on how to provide custom parameters or routing info with that Intent. It's not deep linking unless you specify some depth!
It does specify how to provide Extras through the use of the al_applink_data structure. It does not however say how the target application should provide metadata for the client to consume and send with that structure.
The only suggestion I can think of is to provide the metadata through the optional al:android:url-parameter. So for instance if I'm running a blog, I would provide the URL com.myblog://123, "123" being the ID to a blog entry.
I don't feel like this is an optimal solution. I would then have to parse the URL in order to get the argument. I feel a better solution would be to have a an applink-property named something like al:android:extras where I could give key-value pairs to consume directly. Why is it not implemented this way?
Am I doing it right if I implement metadata-passing the way I described? Is there something I'm missing with regards to the applinks spec?
The original http(s) url is given to you inside al_applink_data under the target_url key, so you can certainly pass metadata that way.
Passing it via the optional al:android:url is also OK.
Lastly, if you have cooperation from the calling app, they can certainly pass data to you via the extras blob.
The reason there's no al:android:extras is that app links was designed to be a routing protocol, and not describe semantics for your app.

action_send mime type for links

When someone longpresses a link and chooses share link and select my app it grabs it and does what it does.. but this also works with other sharable text items. I would like to only accept links. Currently i have the mime type as text/plain. Is there a mime type for links?
No, sorry. At least for the standard Android browser, it uses text/plain. You are welcome to examine the value that is sent to you, see if it looks like a URL via a regular expression, and pop up an error indicating that you only send links.
In theory, you could even then turn around and execute startActivity() for the same Intent, to allow the user to choose something else to try sharing with. I have not tried this, though, so there could be some hiccups here that I am not aware of.

Android Custom URI Handler - Gmail App doesn't recognize?

I'm trying to open a link from my Gmail Application. If I send myapp://custom/params, Gmail only recognizes it as text. I can get the link to open my application "myapp" from a browser, though. How can I get around this?
I'd suggest that you use URIs with the content: scheme and a custom ContentProvider.
See http://developer.android.com/guide/topics/providers/content-providers.html.
I think this comes down to a problem with the way the GMail apps looks for stuff to link up as URLs in the body of a text formatted message. I believe you have two options:
Send the email message as HTML instead of plain text and explicitly href= link to your custom scheme.
Instead of hooking to a custom scheme, setup your app to handle protocol http with the host and path set to something unique. As long as you include the exact path the intent filter shouldn't get in the way of normal browsing to your website.
I haven't tried either of those. #2 I'm pretty definite will work, however #1 might be a bit cleaner depending on your app.

Find out which browsers are installed?

I'm looking for a way to find out which browsers are installed on the Android Smartphone and their package names.
Why do I need it?
Well basically, my App reacts on certain URLs, i.e. http://bit.ly, so when the click such an he will get an choice in which App to open it. So far everything is working as intended.
If the user sets up this app as default for this kind of links, it will always open in this one without further asking the user. So far so good too. But by doing this, he will be completely unable to open this links in his browser.
So I need a way to send this intent directly to the browser, but to do so I have to know which app the user has set to be default for http/https scheme for example (as user can change it if there is more than 1 browser installed).
Sending the intend with
intent.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
should't be a problem I think. The problem is, I can't send a standard intent für URLs, because my App would catch it again if set as default by the user.
should't be a problem I think
Hardwiring in the package and class names of code that is not yours is always a problem.
So I need a way to send this intent directly to the browser, but to do so I have to know which app the user
has set to be default for http/https scheme for example (as user can change it if there is more than 1
browser installed).
Use PackageManager and queryIntentActivityOptions() to filter your activity out and get a list of other activities that the user can choose from.

Categories

Resources