package com.licheng.caller;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.SystemClock;
import android.telephony.SmsManager;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 去除标题
// requestWindowFeature(Window.FEATURE_NO_TITLE);
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
// Thread.sleep(1000);
SystemClock.sleep(1000);
// 短信管理器
SmsManager amsManager = SmsManager.getDefault();
amsManager.sendTextMessage("10086", // 收件人号码
null, // 短信中心号码
"aaa", // 内容
null, // 如果发送成功,回调次广播,通知我们
null); // 对方接收成功,回调此广播。
}
}
}).start();
}
public void call(View v) {
EditText etCall = (EditText) findViewById(R.id.number);
String number = etCall.getText().toString();
Intent intent = new Intent();
intent.setAction(intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + number));
startActivity(intent);
}
// 注:目前有四种方法,其余三种为,匿名内部类, 自写类实现OnclickLisenler接口,Activity直接
// 实现。
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.licheng.caller.MainActivity$PlaceholderFragment" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title" />
<EditText
android:id="@+id/number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:inputType="number"
/>
<Button
android:id="@+id/call"
android:layout_below="@id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/callnumber"
android:textSize="16sp"
android:onClick="call"
/>
</RelativeLayout>
权限:
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.CALL_PHONE" />