Basic usage examples of intent in Android

Source: Internet
Author: User

Package cn.com. chenzheng_java;

Import Android. App. activity;
Import Android. content. intent;
Import android.net. Uri;
Import Android. OS. Bundle;
Import Android. View. view;
Import Android. View. View. onclicklistener;
Import Android. widget. Button;

Public class intentactivity extends activity {
@ Override
Protected void oncreate (bundle savedinstancestate ){
 
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Intent );
Button button = (button) findviewbyid (R. Id. button1 );
Button. setonclicklistener (New onclicklistener (){

@ Override
Public void onclick (view v ){

Sentsms2 ();
}
});
 
 
}
 
Uri URI;
Intent intent;
 
/**
* Open the web page. The implicit itent determines who will respond to the intent (no permission is required)
*/
Private void showwebpage (){
Uri = URI. parse ("http://www.baidu.com ");
Intent = new intent (intent. action_view, Uri );
Startactivity (intent );
}
/***
* Open a Web Map (no permission required)
*/
Private void showmap (){
Uri = URI. parse ("http://maps.google.com/maps? F = D & saddr = startlat % 20 startlng & daddr = endlat % 20 endlng & HL = EN ");
Intent = new intent (intent. action_view, Uri );
Startactivity (intent );
}
/***
* Calls out the dialing main program (no permission is required)
*/
Private void caller (){
Uri = URI. parse ("Tel: 5556 ");
Intent = new intent (intent. action_dial, Uri );
Startactivity (intent );

}
/***
* Directly call the phone. Note that you must first grant the permission Android. Permission. call_phone.
*/
Private void call (){
Uri = URI. parse ("Tel: 5556 ");
Intent = new intent (intent. action_call, Uri );
Startactivity (intent );

}
/**
* Call the SMS sending program (no permission required)
*/
Private void sentsms (){

Intent = new intent (intent. action_view );
Intent. putextra ("sms_body", "the SMS text ");
Intent. settype ("Vnd. Android-DIR/MMS-SMS ");
Startactivity (intent );

}
/**
* Send text messages directly (permission Android. Permission. send_sms needs to be declared)
*/
Private void sentsms2 (){
Uri = URI. parse ("smsto: 5556 ");
Intent = new intent (intent. action_sendto, Uri );
Intent. putextra ("sms_body", "the SMS text ");
// Intent. settype ("Vnd. Android-DIR/MMS-SMS ");
Startactivity (intent );

}
 
 
}

-------------------------------------------------------

Send email

Private void sendemail (string number ){
Intent emailintent = new intent ();
Emailintent. setaction (intent. action_send );
Emailintent. settype ("plain/text ");
// Set the address
Emailintent. putextra (intent. extra_email, "chenzheng_java@163.com ");
Emailintent. putextra (intent. extra_subject, "set topic ");
Emailintent. putextra (intent. extra_title, "title ");
Emailintent. putextra (intent. extra_text, "body content: Incoming call, phone number:" + number );
Startactivity (
Intent. createchooser (emailintent, "lainiu, select an application ")
);
Log. I ("notification", "email sent successfully ");
}

Method 2 URI uri = URI. parse ("mailto: terryyhl@gmail.com ");
Intent mymailintent = new intent (intent. action_send, Uri );
Startactivity (mymailintent );

Method 3 intent testintent = new intent (intent. action_send );
String [] TOS = {"terryyhl@gmail.com "};
String [] CCS = {"kalaicheng@hotmail.com "};
Testintent. putextra (intent. extra_email, TOS );
Testintent. putextra (intent. extra_cc, CCS );
Testintent. putextra (intent. extra_text, "this is content ");
Testintent. putextra (intent. extra_subject, "this is the title ");
Testintent. settype ("message/rfc822 ");
Startactivity (intent. createchooser (testintent, "send "));
Method 4: Upload the attachment. Here we use the SD card music file as an example intent testn = new intent (intent. action_send );
Testn. putextra (intent. extra_subject, "title ");
Testn. putextra (intent. extra_stream, "file: // sdcard/musicloud ");
Startactivity (intent. createchooser (testn, "send "));
Use javamail. Here I will not introduce the implementation method of javamail, if you are interested, you can go here to take a look, online to find a more detailed article http://www.javaeye.com/topic/352753
Because the current simulator does not have a built-in Gmail client program, after the e-mail program sends data, the simulator will send "No application can perform this action". I do not have an Android phone

 

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.