常用的类和方法
android.telephony.TelephonyManager
android.telephony.SmsManager
android.telephony.SmsMessage
android.telephony.PhoneStateListener
获取来电号码 (不要忘了在AndroidManifest.xml中加入权限)
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
telephonyManager.listen(new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber){
Log.e(“PhoneCallState”, “Incoming number “ + incomingNumber); //incomingNumber就是来电号码
}
}, PhoneStateListener.LISTEN_CALL_STATE);
发短信
Uri uri = Uri.parse("smsto:15800001234");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body", "android...");
startActivity(intent);
<uses-permission android:name="android.permission.SEND_SMS"/>
打电话
Uri uri = Uri.parse("tel:15800001234");
Intent intent = new Intent(Intent.ACTION_CALL, uri);
startActivity(intent);
<uses-permission android:name="android.permission.CALL_PHONE" />