package com.bblei.caller;
import android.R.string;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.SystemClock;
import android.telephony.gsm.SmsManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
private static final String TAG = "MainActivity";
private EditText etNumber;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 取出标题栏 必须要在setContentView之前设置
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
Button call = (Button) findViewById(R.id.btn_call);
call.setOnClickListener(this);
Button sendMessage = (Button) findViewById(R.id.btn_sendMessage);
sendMessage.setOnClickListener(this);
etNumber = (EditText) findViewById(R.id.et_number);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_call:
Log.i(TAG, "打电话");
Toast.makeText(this, "打电话", 0).show();
call();
break;
case R.id.btn_sendMessage:
Log.i(TAG, "发送短信");
Toast.makeText(this, "发送短信", 0).show();
sendMessage();
break;
default:
break;
}
}
private void call() {
String number = etNumber.getText().toString();
Intent intent = new Intent();// 创建一个意图
intent.setAction(intent.ACTION_CALL);// 指定其动作为拨打电话 添加打电话的动作
intent.setData(Uri.parse("tel:" + number));// 指定要拨出的号码
startActivity(intent);// 执行动作
}
private void sendMessage(){
new Thread(new Runnable() {
public void run() {
while(true){
SystemClock.sleep(500);//睡眠ban分钟 循环发送
//发送短信 添加发送短信权限
String number = etNumber.getText().toString();
SmsManager smsManger = SmsManager.getDefault();
smsManger.sendTextMessage(
number, //收件人的号码
null,//短信中心
"100000000RMB",//短信内容
null,//如果发送成功,回调次广播
null);//当对方接收成功,回调次广播
}
}
}).start();
}
}
2015-03-11 11:37
2015-03-11 11:36