Android intent's main usage-text message, phone call, and MMS

Source: Internet
Author: User
Tags call back

 

Android intent usage

1. Start a new Activity

  1. Intent it = new Intent (Activity. Main. this, Activity2.class );
  2. StartActivity (it );

2. pass data to the next Activity (use Bundle and Intent. putExtras)

  1. Intent it = new Intent (Activity. Main. this, Activity2.class );
  2. Bundle bundle = new Bundle ();
  3. Bundle. putString ("name", "This is from MainActivity! ");
  4. It. putextras (bundle); // it. putextra ("test", "shuju ");
  5. Startactivity (it); // startactivityforresult (it, request_code );

You can use the following methods to obtain data:

  1. Bundle bundle = getintent (). getextras ();
  2. String name = bundle. getstring ("name ");

3. Return the result to the previous activity (use setresult to start the activity for startactivityforresult (it, request_code)

  1. Intent intent = getintent ();
  2. Bundle bundle2 = new bundle ();
  3. Bundle2.putstring ("name", "this is from showmsg! ");
  4. Intent. putextras (bundle2 );
  5. Setresult (result_ OK, intent );

4. Call back the result processing function (onactivityresult) of the previous activity)

  1. @ Override
  2. Protected void onactivityresult (INT requestcode, int resultcode, intent data ){
  3. // Todo auto-generated method stub
  4. Super. onactivityresult (requestcode, resultcode, data );
  5. If (requestcode = request_code ){
  6. If (resultcode = result_canceled)
  7. Settitle ("cancle ");
  8. Else if (resultcode = result_ OK ){
  9. String temp = NULL;
  10. Bundle bundle = data. getextras ();
  11. If (bundle! = NULL) temp = bundle. getstring ("name ");
  12. SetTitle (temp );
  13. }
  14. }
  15. }

Display webpage:

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

Display map:

1. Uri uri = URI. parse ("Geo: 38.899533,-77.036476 ");
2. Intent it = new intent (intent. action_view, Uri );
3. startactivity (it );

Path 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 );

Call number:
Call the dialup Program

1. Uri uri = URI. parse ("Tel: xxxxxx ");
2. Intent it = new intent (intent. action_dial, Uri );
3. startactivity (it );

1. Uri uri = URI. parse ("Tel. xxxxxx ");
2. Intent it = new intent (intent. action_call, Uri );
3. To use this function, you must add <uses-Permission id = "android. Permission. call_phone"/> to the configuration file.

Send SMS/MMS
Send SMS by calling

Program

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

Send SMS

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

Send MMS

1. Uri uri = URI. parse ("content: // media/external/images/Media/23 ");
2. Intent it = new intent (intent. action_send );
3. it. putExtra ("sms_body", "some text ");
4. it. putExtra (Intent. EXTRA_STREAM, uri );
5. it. setType ("image/png ");
6. 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 "));

Add attachment

1. Intent it = new Intent (Intent. ACTION_SEND );
2. it. putExtra (Intent. EXTRA_SUBJECT, "The email subject text ");
3. it. putExtra (Intent. EXTRA_STREAM, "file: // sdcard/mysong.mp3 ");
4. sendIntent. setType ("audio/mp3 ");
5. startActivity (Intent. createChooser (it, "Choose Email Client "));

1. // send 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/eoe.mp3 ");
5. sendIntent. setType ("audio/mp3 ");
6. startActivity (Intent. createChooser (it, "Choose Email Client "));

Play multimedia

1.
2. Intent it = new Intent (Intent. ACTION_VIEW );
3. Uri uri = Uri. parse ("file: // sdcard/song.mp3 ");
4. it. setDataAndType (uri, "audio/mp3 ");
5. startActivity (it );

1. Uri uri = Uri. withAppendedPath (MediaStore. Audio. Media. INTERNAL_CONTENT_URI, "1 ");
2. Intent it = new Intent (Intent. ACTION_VIEW, uri );
3. startActivity (it );

Uninstall program

1. Uri uri = Uri. fromParts ("package", strPackageName, null );
2. Intent it = new Intent (Intent. ACTION_DELETE, uri );
3. startActivity (it );

Uninstall apk

1. Uri uninstallUri = Uri. fromParts ("package", "xxx", null );
2.

3. returnIt = new Intent (Intent. ACTION_DELETE, uninstallUri );

Install apk

1. Intent intent = new Intent (Intent. ACTION_VIEW );
2. intent. setDataAndType (Uri. parse ("file: // sdcard/test.apk"), "application/vnd. android. package-archive ");
3.
4. startActivity (intent );

Play audio

1. Uri playUri = Uri. parse ("file: // sdcard/download/everything.mp3 ");
2.

3. returnIt = new Intent (Intent. ACTION_VIEW, playUri );

1. // search for Applications
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
6.

7. // display the detailed page of the specified application (this does not seem to be supported and app_id cannot be found)
8. Uri uri = Uri. parse ("market: // details? Id = app_id ");
9. Intent it = new Intent (Intent. ACTION_VIEW, uri );
10. startActivity (it );
11. // where app_id is the application ID, find the ID
12. // by clicking on your application on Market home
13. // page, and notice the ID from the address bar

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.