Intent and intent-filter usage

Source: Internet
Author: User
Intentfilter
Description: Describes intent matching information in a structured manner. Include: Action, categories and data (via type, scheme, PATH), and priority, to order Multiple matching filters.
If action is null in intentfilter, it is considered as a wildcard. If type is null, intent must not have a type; otherwise, it cannot match.
Data is divided into three attributes: type, scheme, authority/path. Any set attribute intent must match.
If scheme is set but type is not set, intent must be similar. Neither type nor content: URI.
If type is set but scheme is not set, intent without Uri, or Uri with content:, file: Will be matched.
Set authority: one or more associated schemes must be specified.
Path: specifies one or more associated schemes.
Matching rules:
Intentfilter matches the conditions on intent:
Action: The value is the same, or action is not specified in intentfilter.
Datatype:. The system calls intent. Resolve (contentresolver) to obtain the type and wildcard *
Used in the MIME type of intent/intentfilter, case sensitive
Datascheme: The system calls intent. getdata () and Uri. getscheme () to obtain scheme, case sensitive.

Dataauthority: there must be a datascheme matched with the Authority value, or the intentfilter is not defined.
Intent. getdata () and Uri. getauthority () Get authority.
Datapath: Scheme and authority must match ntent. getdata () and Uri. getpath () first. The. Or intentfilter is not defined.

Categories: All of the categories in the intent match categories given
In the filter, the redundant categorie does not affect intent matching. If intentfilter
If no categorie is specified, only intent without categorie can be matched.

Common intent list:
Android intent usage Summary
Display webpage
-
<Activity Android: Name = "browseractivity" Android: Label = "Browser"
Android: launchmode = "singletask" Android: alwaysretaintaskstate = "true"
Android: configchanges = "orientation | keyboardhidden"
Android: theme = "@ style/browsertheme">
-<! --
For these schemes were not particle MIME type has been
Supplied, we are a good candidate.
-->
-<Intent-filter>
<Action Android: Name = "android. Intent. Action. View"/>
<Category Android: Name = "android. Intent. Category. Default"/>
<Category Android: Name = "android. Intent. Category. browsable"/>
<Data Android: Scheme = "HTTP"/>
<Data Android: Scheme = "HTTPS"/>
<Data Android: Scheme = "about"/>
</Intent-filter>
-<! --
For these schemes where any of these participant ular MIME types
Have been supplied, we are a good candidate.
-->
-<Intent-filter>
<Action Android: Name = "android. Intent. Action. View"/>
<Category Android: Name = "android. Intent. Category. browsable"/>
<Category Android: Name = "android. Intent. Category. Default"/>
<Data Android: Scheme = "HTTP"/>
<Data Android: Scheme = "HTTPS"/>
<Data Android: mimetype = "text/html"/>
<Data Android: mimetype = "text/plain"/>
<Data Android: mimetype = "application/XHTML + XML"/>
<Data Android: mimetype = "application/vnd.wap.xhtml + XML"/>
</Intent-filter>
-<! --
We are also the main entry point of the browser.
-->
-<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. Default"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
<Category Android: Name = "android. Intent. Category. browsable"/>
</Intent-filter>
-<Intent-filter>
<Action Android: Name = "android. Intent. Action. web_search"/>
<Category Android: Name = "android. Intent. Category. Default"/>
<Category Android: Name = "android. Intent. Category. browsable"/>
<Data Android: Scheme = ""/>
<Data Android: Scheme = "HTTP"/>
<Data Android: Scheme = "HTTPS"/>
</Intent-filter>
-<Intent-filter>
<Action Android: Name = "android. Intent. Action. web_search"/>
<Action Android: Name = "android. Intent. Action. media_search"/>
<Category Android: Name = "android. Intent. Category. Default"/>
</Intent-filter>
-<Intent-filter>
<Action Android: Name = "android. Intent. Action. Search"/>
<Category Android: Name = "android. Intent. Category. Default"/>
</Intent-filter>
<Meta-data Android: Name = "android. App. searchable" Android: Resource = "@ XML/searchable"/>
-<Intent-filter>
<Action Android: Name = "android.net. http. network_state"/>
<Action Android: Name = "android. Intent. Action. proxy_change"/>
</Intent-filter>
</Activity>

1. Uri uri = URI. parse ("http://google.com ");
2. Intent it = new intent (intent. action_view, Uri );
3. startactivity (it );

Show Map

1. Uri uri = URI. parse ("Geo: 38.899533,-77.036476 ");
2. Intent it = new intent (intent. action_view, Uri );
3. startactivity (it );
4. // other geo uri examples
5. // GEO: latitude, longpolling
6. // GEO: latitude, longpolling? Z = zoom
7. // GEO: 0, 0? Q = My + street + address
8. // GEO: 0, 0? Q = business + near + city
9. // Google. Streetview: cbll = Lat, LNG & white = 1, yaw, pitch, zoom & MZ = mapzoom

Route Planning


1. Uri uri =
Uri. parse ("http://maps.google.com/maps? F = D & saddr = startlat % 20 startlng & daddr = endlat % 20 endlng & HL = EN ");

2. Intent it = new intent (intent. action_view, Uri );
3. startactivity (it );
4. // Where startlat, startlng, endlat, endlng are a long with 6 decimals like: 50.123456

Call
1. // outbound dialingProgram
2. Uri uri = URI. parse ("Tel: 0800000123 ");
3. Intent it = new intent (intent. action_dial, Uri );
4. startactivity (it );

1. // directly call
2. Uri uri = URI. parse ("Tel: 0800000123 ");
3. Intent it = new intent (intent. action_call, Uri );
4. startactivity (it );
5. // use this file, which must be added to androidmanifest. xml.
6. // <uses-Permission id = "android. Permission. call_phone"/>

Send SMS/MMS
1. // call the SMS Program
2. Intent it = new intent (intent. action_view, Uri );
3. It. putextra ("sms_body", "the SMS text ");
4. It. settype ("Vnd. Android-DIR/MMS-SMS ");
5. startactivity (it );

1. // send messages
2. Uri uri = URI. parse ("smsto: // 0800000123 ");
3. Intent it = new intent (intent. action_sendto, Uri );
4. It. putextra ("sms_body", "the SMS text ");
5. startactivity (it );

1. // send MMS
2. Uri uri = URI. parse ("content: // media/external/images/Media/23 ");
3. Intent it = new intent (intent. action_send );
4. It. putextra ("sms_body", "some text ");
5. It. putextra (intent. extra_stream, Uri );
6. It. settype ("image/PNG ");
7. startactivity (it );

Send email
1. Uri uri = URI. parse ("mailto: xxx@abc.com ");
2. Intent it = new intent (intent. action_sendto, Uri );
3. startactivity (it );

1. Intent it = new intent (intent. action_send );
2. it. putextra (intent. extra_email, "me@abc.com ");
3. It. putextra (intent. extra_text, "the email body text ");
4. It. settype ("text/plain ");
5. startactivity (intent. createchooser (IT, "Choose email client "));

1. intent it = new intent (intent. action_send);
2. string [] TOS = {"me@abc.com"};
3. string [] CCS = {"you@abc.com"};
4. it. putextra (intent. extra_email, TOS);
5. it. putextra (intent. extra_cc, CCS);
6. it. putextra (intent. extra_text, "the email body text");
7. it. putextra (intent. extra_subject, "the email subject text");
8. it. settype ("message/rfc822");
9. startactivity (intent. createchooser (IT, "Choose email client");

1. // transfer the attachment
2. Intent it = new intent (intent. action_send );
3. It. putextra (intent. extra_subject, "the email subject text ");
4. It. putextra (intent. extra_stream, "file: // sdcard/mysong.mp3 ");
5. sendintent. settype ("audio/MP3 ");
6. startactivity (intent. createchooser (IT, "Choose email client "));

Play multimedia
Uri uri = URI. parse ("file: // sdcard/song.mp3 ");
Intent it = new intent (intent. action_view, Uri );
It. settype ("audio/MP3 ");
Startactivity (it );

Uri uri = URI. withappendedpath (mediastore. Audio. Media. internal_content_uri, "1 ");
Intent it = new intent (intent. action_view, Uri );

Startactivity (it );

Market Problems
1. // search for an application
2. Uri uri = URI. parse ("Market: // search? Q = pname: pkg_name ");
3. Intent it = new intent (intent. action_view, Uri );
4. startactivity (it );
5. // Where pkg_name is the full package path for an application

1. // display information about an application
2. Uri uri = URI. parse ("Market: // details? Id = app_id ");
3. intent it = new intent (intent. action_view, Uri);
4. startactivity (it);
5. // Where app_id is the Application ID, find the id
6. // by clicking on your application on market Home
7. // page, and notice the ID from the address bar

uninstall application
1. uri uri = Uri. fromparts ("package", strpackagename, null);
2. intent it = new intent (intent. action_delete, Uri);
3. startactivity (it);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.