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 ;
/**
* 打开web网页.隐式的Itent,有系统决定由谁来响应该intent(不用赋予权限)
*/
private void showWebPage(){
uri = Uri.parse("http://www.baidu.com");
intent = new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);
}
/***
* 打开web地图(不用赋予权限)
*/
private void showMap(){
uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
intent = new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);
}
/***
* 调出来拨号主程序(不用赋予权限)
*/
private void caller(){
uri = Uri.parse("tel:5556");
intent = new Intent(Intent.ACTION_DIAL,uri);
startActivity(intent);
}
/***
* 直接打出去电话,注意这里要先赋予权限 android.permission.CALL_PHONE
*/
private void call(){
uri = Uri.parse("tel:5556");
intent = new Intent(Intent.ACTION_CALL,uri);
startActivity(intent);
}
/**
* 调用发送短信程序(不用赋予权限)
*/
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);
}
/**
* 直接发送短信(需要声明权限android.permission.SEND_SMS)
*/
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);
}
}
-------------------------------------------------------
发送邮件
private void sendEmail(String number){
Intent emailIntent = new Intent();
emailIntent.setAction(Intent.ACTION_SEND);
emailIntent.setType("plain/text");
// 设置地址
emailIntent.putExtra(Intent.EXTRA_EMAIL, "chenzheng_java@163.com");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "设置主题");
emailIntent.putExtra(Intent.EXTRA_TITLE, "标题");
emailIntent.putExtra(Intent.EXTRA_TEXT, "正文内容:来电了,电话号码为"+number);
startActivity(
Intent.createChooser(emailIntent, "来妞,选择个应用")
);
Log.i("通知", "email发送成功");
}
方法二 Uri uri=Uri.parse("mailto:terryyhl@gmail.com");
Intent MymailIntent=new Intent(Intent.ACTION_SEND,uri);
startActivity(MymailIntent);
方法三 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, "这是内容");
testintent.putExtra(Intent.EXTRA_SUBJECT, "这是标题");
testintent.setType("message/rfc822");
startActivity(Intent.createChooser(testintent, "发送"));
方法四,传附件,这里以SD卡的音乐文件为例 Intent testN=new Intent(Intent.ACTION_SEND);
testN.putExtra(Intent.EXTRA_SUBJECT, "标题");
testN.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/music.mp3");
startActivity(Intent.createChooser(testN, "发送"));
使用javamail。这里我就不介绍javamail的实现方法了,有兴趣的话可以到这里看一下,网上找到的一篇比较详细的文章http://www.javaeye.com/topic/352753
由于目前模拟器未内置Gmail Client端程序,因此发送Email程序在送出数据后,模拟器上会发出 “No Application can perform this action”,本人没有Android手机