package com.example.project_activity;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity implements OnClickListener {
private Button button1;
private Button button2;
private Button button3;
private Button button4;
private Button button5;
private Button button6;
private Button button7;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findView();
button1.setOnClickListener(this);
button2.setOnClickListener(this);
button3.setOnClickListener(this);
button4.setOnClickListener(this);
button5.setOnClickListener(this);
button6.setOnClickListener(this);
button7.setOnClickListener(this);
}
void findView()
{
button1=(Button)findViewById(R.id.button1);//拨号
button2=(Button)findViewById(R.id.button2);// 调用拨号程序
button3=(Button)findViewById(R.id.button3);// 浏览网页
button4=(Button)findViewById(R.id.button4);// E-mail
button5=(Button)findViewById(R.id.button5);// sendE-mail
button6=(Button)findViewById(R.id.button6);// 查看联系人
button7=(Button)findViewById(R.id.button7);//显示系统设置界面
}
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
switch (view.getId()) {
case R.id.button1:
dialMethod();
break;
case R.id.button2:
touchDialerIntent();
break;
case R.id.button3:
webIntent("http://baidu.com");
break;
case R.id.button4:
E_mail();//BUG
break;
case R.id.button5:
sendEmail();
break;
case R.id.button6:
contactListIntent();
break;
case R.id.button7:
settingIntent();
break;
default:
break;
}
}
/**
* 讲电话传入拨号程序
*/
private void dialMethod()
{
Intent callIntent=new Intent(Intent.ACTION_DIAL,Uri.parse("tel:13171451826"));
startActivity(callIntent);
}
/**
* 调用拨号程序
* ——如果不想将电话传入拨号程序,而只想启动拨号程序,可以使用如下的程序
*/
private void touchDialerIntent()
{
Intent touchDialerIntent=new Intent("com.android.phone.action.TOUCH_DIALER");
startActivity(touchDialerIntent);
}
/**
* 浏览网页
* ——Android SDK内置的Web浏览器也对外提供了Action
*/
private void webIntent(String url)
{
Intent webIntent=new Intent(Intent.ACTION_VIEW,Uri.parse(url));
startActivity(webIntent);
}
/**
* 向E—mail客户端传递E-mail地址
* ——在向E-mail客户端fasongE-mail地址时应在手机或模拟器中至少配置一个E-mail。
* 否则系统无法显示E-mail客户端界面
*/
private void E_mail()
{
Uri uri=Uri.parse("emailto:779359321@qq.com");
Intent intent=new Intent(Intent.ACTION_SENDTO,uri);
startActivity(intent);
}
private void sendEmail()
{
Intent sendEmialIntent=new Intent(Intent.ACTION_SEND);
//指定要发送的目标E-mail
sendEmialIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"779359321@qq.com"});
//指定抄送的E-mail地址
sendEmialIntent.putExtra(Intent.EXTRA_CC, new String[]{"2567827112@qq.com"});
//指定E-mail标题
sendEmialIntent.putExtra(Intent.EXTRA_SUBJECT, "关于Android的相关问题");
//指定E-mail内容
sendEmialIntent.putExtra(Intent.EXTRA_TEXT, "关于Android的相关问题解决办法");
//指定E-mail的内容是纯文本
sendEmialIntent.setType("text/plain");
//建立一个自定义选择器,并有客户选择使用哪一个客户端发送消息
startActivity(Intent.createChooser(sendEmialIntent, "选择发送消息的客户端"));
}
/**
* 显示系统设置界面
*/
private void settingIntent()
{
Intent settingIntent=new Intent("android.settings.SETTINGS");
// Intent wifiIntent=new Intent("android.settings.WIFI_SETTINGS");//显示WIFI设置界面
startActivity(settingIntent);
}
/**
* 查看联系人
* @author x
* @category 大
*/
private void contactListIntent()
{
Intent contactListIntent=new Intent("com.android.contacts.action.LIST_CONTACTS");
startActivity(contactListIntent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}