Example of Intent. Action in common Android Systems

Source: Internet
Author: User

Example of Intent. Action in common Android Systems
ACTION_MAIN android. intent. action. MAIN application portal
ACTION_VIEW android. intent. action. VIEW displays data to users.
ACTION_ATTACH_DATA android. intent. action. ATTACH_DATA specifies the data to be appended to other places.
ACTION_EDIT android. intent. action. EDIT: Display editable data
ACTION_PICK android. intent. action. PICK select data
ACTION_CHOOSER android. intent. action. CHOOSER displays an Activity selector.
ACTION_GET_CONTENT android. intent. action. GET_CONTENT get content
ACTION_DIAL android. intent. action. GET_CONTENT: display the call panel
ACITON_CALL android. intent. action. DIAL
ACTION_SEND android. intent. action. SEND a text message directly
ACTION_SENDTO android. intent. action. SENDTO select to send text messages
ACTION_ANSWER android. intent. action. ANSWER
ACTION_INSERT android. intent. action. INSERT data
ACTION_DELETE android. intent. action. DELETE data
ACTION_RUN android. intent. action. RUN data
ACTION_SYNC android. intent. action. SYNC synchronize data
ACTION_PICK_ACTIVITY android. intent. action. PICK_ACTIVITY select Activity
ACTION_SEARCH android. intent. action. SEARCH
ACTION_WEB_SEARCH android. intent. action. WEB_SEARCH Web Search

ACTION_FACTORY_TEST android. intent. action. FACTORY_TEST factory test entry point

------------------------------------ Layout file ----------------------------------------------------------

Xmlns: tools = http://schemas.android.com/tools
Android: layout_width = match_parent
Android: layout_height = match_parent>

Android: layout_width = match_parent
Android: layout_height = wrap_content
Android: orientation = vertical>

Android: layout_width = wrap_content
Android: layout_height = wrap_content
Android: layout_gravity = center
Android: layout_marginTop = 5dp
Android: text = commonly used Android system Intent/>

Android: id = @ + id/intent_call_btn
Android: layout_width = match_parent
Android: layout_height = wrap_content
Android: layout_marginTop = 2dp
Android: text = call/>

Android: id = @ + id/intent_sms_btn
Android: layout_width = match_parent
Android: layout_height = wrap_content
Android: layout_marginTop = 2dp
Android: text = send SMS/>

Android: id = @ + id/intent_email_btn
Android: layout_width = match_parent
Android: layout_height = wrap_content
Android: layout_marginTop = 2dp
Android: text = Send email/>

Android: id = @ + id/intent_net_btn
Android: layout_width = match_parent
Android: layout_height = wrap_content
Android: layout_marginTop = 2dp
Android: text = open web page/>

Android: id = @ + id/intent_pic_btn
Android: layout_width = match_parent
Android: layout_height = wrap_content
Android: layout_marginTop = 2dp
Android: text = Send an image/>

Android: id = @ + id/intent_media_btn
Android: layout_width = match_parent
Android: layout_height = wrap_content
Android: layout_marginTop = 2dp
Android: text = Open Media/>

Android: id = @ + id/intent_search_btn
Android: layout_width = match_parent
Android: layout_height = wrap_content
Android: layout_marginTop = 2dp
Android: text = search/>

Android: id = @ + id/intent_install_btn
Android: layout_width = match_parent
Android: layout_height = wrap_content
Android: layout_marginTop = 2dp
Android: text = install software/>

Android: id = @ + id/intent_unstall_btn
Android: layout_width = match_parent
Android: layout_height = wrap_content
Android: layout_marginTop = 2dp
Android: text = uninstall software/>


 

---------------------------- Activity code --------------------------------------------------------

Public class MainActivity extends Activity implements OnClickListener {
Private Button callBtn;
Private Button smsBtn;
Private Button emailBtn;
Private Button browseBtn;
Private Button searchBtn;
Private Button installBtn;
Private Button unInstallBtn;
Private Button mediaBtn;
Private Button picBtn;


@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_main );
InitViewsById ();
InitListeners ();
}


Private void initViewsById (){
CallBtn = (Button) findViewById (R. id. intent_call_btn );
SmsBtn = (Button) findViewById (R. id. intent_sms_btn );
EmailBtn = (Button) findViewById (R. id. intent_email_btn );
BrowseBtn = (Button) findViewById (R. id. intent_net_btn );
PicBtn = (Button) findViewById (R. id. intent_pic_btn );
InstallBtn = (Button) findViewById (R. id. intent_install_btn );
UnInstallBtn = (Button) findViewById (R. id. intent_unstall_btn );
MediaBtn = (Button) findViewById (R. id. intent_media_btn );
SearchBtn = (Button) findViewById (R. id. intent_search_btn );
}


Private void initListeners (){
CallBtn. setOnClickListener (this );
SmsBtn. setOnClickListener (this );
EmailBtn. setOnClickListener (this );
BrowseBtn. setOnClickListener (this );
PicBtn. setOnClickListener (this );
InstallBtn. setOnClickListener (this );
UnInstallBtn. setOnClickListener (this );
MediaBtn. setOnClickListener (this );
SearchBtn. setOnClickListener (this );
}


/** Browser */
Private void netBrowse (){
/** Address */
Uri uri = Uri. parse (http://www.baidu.com );
Intent intent = new Intent (Intent. ACTION_VIEW, uri );
StartActivity (intent );
}


/** Video */
Private void playMedia (){
/** Uri */
Uri uri = Uri. withAppendedPath (MediaStore. Audio. Media. INTERNAL_CONTENT_URI, 1 );
Intent intent = new Intent (Intent. ACTION_VIEW, uri );
StartActivity (intent );
}


/** Search */
Private void search (){
Intent intent = new Intent ();
Intent. setAction (Intent. ACTION_WEB_SEARCH );
Intent. putExtra (SearchManager. QUERY, android );
StartActivity (intent );
}


/** Call */
Private void callTelphone (){
/** Phone number */
Uri uri = Uri. parse (tel: 10086 );
Intent intent = new Intent (Intent. ACTION_DIAL, uri );
StartActivity (intent );
}


/** Send a text message Activity */
Private void sendSms (){
Uri uri = Uri. parse (smsto: 10086 );
Intent intent = new Intent (Intent. ACTION_SENDTO, uri );
StartActivity (intent );
}


/** Send an image (MMS )*/
@ SuppressLint (SdCardPath)
Private void sendPicSms (){
/** Image Position */
Uri imguri = Uri. parse (/mnt/sdcard/abc.png );
Intent intent = new Intent (Intent. ACTION_SEND );
/** Image Stream Data */
Intent. putExtra (Intent. EXTRA_STREAM, imguri );
/** Specify the type */
Intent. setType (image/png );
StartActivity (Intent. createChooser (intent, Send Image :));
}


/** Send an email */
Private void sendEmail (){
Intent intent = new Intent (Intent. ACTION_SEND );
/** Recipient */
String [] to = {shoujianren@163.com };
Intent. putExtra (Intent. EXTRA_EMAIL, );
/** CC */
String [] cc = {chaosong@163.com };
Intent. putExtra (Intent. EXTRA_CC, cc );
/** Subject */
Intent. putExtra (Intent. EXTRA_SUBJECT, friend, hello !);
/** Email content */
Intent. putExtra (Intent. EXTRA_TEXT, a lot of content ........);
/** Type/format */
Intent. setType (message/rfc822 );
StartActivity (Intent. createChooser (intent, please select the client mailbox !));
}


/** Install the application */
Private void installSotf (){
/** Address */
Intent intent = new Intent (Intent. ACTION_VIEW );
/** Specify the apk file path */
Intent. setDataAndType (Uri. fromFile (new File (/mnt/sdcard/tutu.apk), application/vnd. android. package-archive );
StartActivity (intent );
}


/** Uninstall the application */
Private void uninstallSoft (){
Uri uri = Uri. fromParts (package, tutu. ch05, null );
Intent it = new Intent (Intent. ACTION_DELETE, uri );
StartActivity (it );
}


@ Override
Public void onClick (View v ){
Switch (v. getId ()){
Case R. id. intent_call_btn:
CallTelphone ();
Break;
Case R. id. intent_sms_btn:
SendSms ();
Break;
Case R. id. intent_email_btn:
SendEmail ();
Break;
Case R. id. intent_pic_btn:
SendPicSms ();
Break;
Case R. id. intent_net_btn:
NetBrowse ();
Break;
Case R. id. intent_search_btn:
Search ();
Break;
Case R. id. intent_install_btn:
InstallSotf ();
Break;
Case R. id. intent_unstall_btn:
UninstallSoft ();
Break;
Case R. id. intent_media_btn:
PlayMedia ();
Break;
}
}
}

 


Related Article

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.