package com.ken.phone;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.widget.TextView;
public class Phone_mailActivity extends Activity {
private TextView mTextView1;
private String mEditText01="850172006@qq.com";
private String strEmailSubject="You have phone!";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mPhoneCallListener phoneCallListener=new mPhoneCallListener();
/*
* 设置TelephonyMangaer去抓取系统的TELEPHONY_SERVICE
*/
TelephonyManager telMgr=(TelephonyManager)getSystemService(TELEPHONY_SERVICE);
telMgr.listen(phoneCallListener,mPhoneCallListener.LISTEN_CALL_STATE);
mTextView1=(TextView)findViewById(R.id.tv);
}
//使用PhoneCallListener来聆听电话状态的更改事件
public class mPhoneCallListener extends PhoneStateListener{
@Override
public void onCallStateChanged(int state, String incomingNumber) {
// TODO Auto-generated method stub
switch(state){
//取得电话待机状态
case TelephonyManager.CALL_STATE_IDLE:
mTextView1.setText(R.string.str_CALL_STATE_IDLE);
break;
//取得电话通话状态
case TelephonyManager.CALL_STATE_OFFHOOK:
mTextView1.setText(R.string.str_CALL_STATE_OFFHOOK);
break;
//取得电话来电状态
case TelephonyManager.CALL_STATE_RINGING:
mTextView1.setText(
//显示来电号码
getResources().getText(R.string.str_CALL_STATE_RINGING)+incomingNumber);
//设置来电时发送邮件
Intent mEmailIntent=new Intent(android.content.Intent.ACTION_SEND);
mEmailIntent.setType("plain/text");
//设置收件人信箱
mEmailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{mEditText01.toString()});
//设置email的标题
mEmailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,strEmailSubject);
//设置email的内容
mEmailIntent.putExtra(android.content.Intent.EXTRA_TEXT, R.string.str_EmailBody+incomingNumber);
//发信
startActivity(Intent.createChooser(mEmailIntent,getResources().getString(R.string.str_message)));
break;
default:
break;
}
super.onCallStateChanged(state, incomingNumber);
}
}
}
在真机上无作用,寻找问题中...