Mime Type / Intent Filter

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

Mime Type / Intent Filter

Postby hobbs » Sun Nov 18, 2007 6:44 pm

Is there a way to listen to and log all Intent Broadcasts? I ask because I would like to be able to create an app that would launch when the browser encounters a specific file type.

Doing some research it looks like I need to have an intent listener with the correct IntentFilter. With the filter, the "Action" and "Category" must match, and the "Type" or "Scheme" must match. I know the "type" portion of the IntentFilter (just the mime-type), but I cannot figure out what the Action and Category is when/if the browser broadcasts an intent when it encounters an unknown file type.

I don't even really know if the browser creates an intent broadcast when it encounters and unknown type...any help on this issue would be much appreciated!

P.S. - Site looks great, good job!
Zach Hobbs
HelloAndroid.com
hobbs
Freshman
Freshman
 
Posts: 4
Joined: Sun Nov 18, 2007 6:35 pm

Top

Re: Mime Type / Intent Filter

Postby plusminus » Sun Nov 18, 2007 7:54 pm

hobbs wrote:Is there a way to listen to and log all Intent Broadcasts? I ask because I would like to be able to create an app that would launch when the browser encounters a specific file type.

Doing some research it looks like I need to have an intent listener with the correct IntentFilter. With the filter, the "Action" and "Category" must match, and the "Type" or "Scheme" must match. I know the "type" portion of the IntentFilter (just the mime-type), but I cannot figure out what the Action and Category is when/if the browser broadcasts an intent when it encounters an unknown file type.

I don't even really know if the browser creates an intent broadcast when it encounters and unknown type...any help on this issue would be much appreciated!

P.S. - Site looks great, good job!


Thanks for your laud :)

I think you are on the very right way :!:
You are exaclty right, you need an IntentReceiver with the appropriate IntentFilter.
But which o_O...
This is probably the Full List of Actions and Categories:
Standard Activity Actions

These are the current standard actions that Intent defines for launching activities (usually through startActivity(Intent). The most important, and by far most frequently used, are MAIN_ACTION and EDIT_ACTION.

* MAIN_ACTION
* VIEW_ACTION
* EDIT_ACTION
* PICK_ACTION
* GET_CONTENT_ACTION
* DIAL_ACTION
* CALL_ACTION
* SENDTO_ACTION
* ANSWER_ACTION
* INSERT_ACTION
* DELETE_ACTION
* RUN_ACTION
* LOGIN_ACTION
* CLEAR_CREDENTIALS_ACTION
* SYNC_ACTION
* PICK_ACTIVITY_ACTION
* WEB_SEARCH_ACTION

Standard Broadcast Actions

These are the current standard actions that Intent defines for receiving broadcasts (usually through registerReceiver(IntentReceiver, IntentFilter) or a <receiver> tag in a manifest).

* TIME_TICK_ACTION
* TIME_CHANGED_ACTION
* TIMEZONE_CHANGED_ACTION
* BOOT_COMPLETED_ACTION
* PACKAGE_ADDED_ACTION
* PACKAGE_REMOVED_ACTION
* BATTERY_CHANGED_ACTION

Standard Categories

These are the current standard categories that can be used to further clarify an Intent via addCategory(String).

* DEFAULT_CATEGORY
* BROWSABLE_CATEGORY
* TAB_CATEGORY
* ALTERNATIVE_CATEGORY
* SELECTED_ALTERNATIVE_CATEGORY
* LAUNCHER_CATEGORY
* HOME_CATEGORY
* PREFERENCE_CATEGORY
* GADGET_CATEGORY
* TEST_CATEGORY


I think that when the browser sends out an Intent, it would probably be no BroadCast intent, as there is no appropriate action, but I think you've meant the right thing.

I think the best "competitors" are "VIEW_ACTION" and "RUN_ACTION", but I think it will be VIEW_ACTION, because its Javadoc says:

Display the data to the user. This is the most common action performed on data -- it is the generic action you can use on a piece of data to get the most reasonable thing to occur. For example, when used on a contacts entry it will view the entry; when used on a mailto: URI it will bring up a compose window filled with the information supplied by the URI; when used with a tel: URI it will invoke the dialer.


Be there are too many assumptions to find the solution in a straight way.

The simples way of finding the truth would be setting up a kind of Logger, as you said...
I'll have a look if I can find sth... :!:
Inform us please, if you did so. :)

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby hobbs » Mon Nov 19, 2007 5:23 am

Looking at the LogCat window I see that it is using the VIEW_ACTION:
I/ActivityManager(480): Starting activity: Intent { action=android.intent.action.VIEW data=http://helloandroid.com/rss.xml comp={com.google.android.browser/com.google.android.browser.BrowserActivity} }

The activity just displays the "unknown type" error at that point. I have found that supplying a type is pointless for a call like this, because according to the docs:
For data that is not a content: URI and where no explicit type is included in the Intent, instead the scheme of the intent data (such as http: or mailto:) is considered. Again like the action, if we are matching a scheme it must be listed by the component as one it can handle.


So, I'm at a loss as far as how this is supposed to be handled...
Zach Hobbs
HelloAndroid.com
hobbs
Freshman
Freshman
 
Posts: 4
Joined: Sun Nov 18, 2007 6:35 pm

Postby plusminus » Mon Nov 19, 2007 8:27 am

Hey hobbs,

:idea: can we place an RegularExpression as the scheme or does it have to be the "startswith" :?:

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby hobbs » Mon Nov 19, 2007 8:35 am

Looks like it's whatever is before the ":". It has to match ContentURI.getScheme() which says:
public String getScheme()
Retrieve the scheme of the URI. This is a simple call through to getScheme().
Returns

* The scheme without the trailing ':' (such as http) of the URI.
Zach Hobbs
HelloAndroid.com
hobbs
Freshman
Freshman
 
Posts: 4
Joined: Sun Nov 18, 2007 6:35 pm

Postby plusminus » Mon Nov 19, 2007 8:43 am

Hm catching any outgoing Intent "http", "https" and "ftp" would be like overkill :?:
Is there nothing else to be matched except the Scheme in our case :?:
Thats pretty weird...

:!: If not, we could receive all those intents, run our own pattern on it and if it doesn't match, send it out again.
But as the IntentFilter itself should handle that, this would be no really good solution, doing that in code...

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby lordhong » Tue Nov 27, 2007 5:25 pm

hobbs wrote:Looks like it's whatever is before the ":". It has to match ContentURI.getScheme() which says:
public String getScheme()
Retrieve the scheme of the URI. This is a simple call through to getScheme().
Returns

* The scheme without the trailing ':' (such as http) of the URI.


you cannot use RegExp for the Scheme here. android expects a String here for the URI.

it looks like it can be absolute (starts with sth. like http:// | file:// | scp:// ?? I'm just guessing), and can have ? in URI for query strings. the URI can also be relative w/o the protocol prefix, but not sure what's the default protocol. maybe localhost as default?
lordhong
Developer
Developer
 
Posts: 42
Joined: Thu Nov 22, 2007 5:25 am
Location: New York

Postby plusminus » Tue Nov 27, 2007 8:04 pm

lordhong wrote:it looks like it can be absolute (starts with sth. like http:// | file:// | scp:// ?? I'm just guessing), and can have ? in URI for query strings. the URI can also be relative w/o the protocol prefix, but not sure what's the default protocol. maybe localhost as default?


Yes, it starts with the scheme, which is sth. like you mentioned ( http:(//) | tel: | file:(/) ...), folowed by ssp (=scheme specific data) which can have query Strings in it. There can also be a fragment at the end (which is automatically escaped), which is seperated with a "#".

Don't know what you mean with 'localhost' as 'default protocal' but I think contentURIs without a scheme are not possible.
The ContentURI constructor will probably throw an Exception, if you try to pass a String containing no scheme... (java.net.URISyntaxException if the string doesn't match the URI specification.).

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Asgard » Thu Dec 27, 2007 3:30 pm

Hi all. Did you succeed in writing this kind of application?
Catch the moment
Asgard
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sat Dec 15, 2007 8:49 pm

Postby Berzerk » Wed Mar 11, 2009 6:26 am

This is from 2007 and there is still no further info...

Any insight on this topic? Anyone?
Berzerk
Freshman
Freshman
 
Posts: 3
Joined: Tue Mar 10, 2009 5:50 am

Top

Return to General

Who is online

Users browsing this forum: Google [Bot] and 4 guests