Android intent usage Summary
Blog type:
Androidgooglef #
Display webpage
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" };< br>
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 );
Define permissions:
- <Uses-Permission Android: Name="Android. Permission. call_phone" />
- <Uses-Permission Android: Name="Android. Permission. send_sms"/>