android电话应用基础知识点
package com.phone;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Menu;
public class PhoneActivity extends Activity {
private static final String TAG = "PhoneActivity";
TelephonyManager telephonyManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_phone);
telephonyManager = (TelephonyManager) get**Service(Context.TELEPHONY_SERVICE);
hardware();
readPhoneInfo();
}
//检查设备是否有电话硬件
private void hardware(){
PackageManager pm = getPackageManager();
boolean hardwareSupported = pm.has**Feature(PackageManager.FEATURE_TELEPHONY);
Log.d(TAG,hardwareSupported+"");
boolean gsmSupported = pm.has**Feature(PackageManager.FEATURE_TELEPHONY_GSM);
Log.d(TAG,gsmSupported+"");
boolean cdmaSupported = pm.has**Feature(PackageManager.FEATURE_TELEPHONY_CDMA);
Log.d(TAG, cdmaSupported+"");
}
//启动拨号activity
private void startCall(){
Intent intent = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:5556"));
startActivity(intent);
}
private void call(){
Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:5556"));
startActivity(intent);
}
private void readPhoneInfo(){
if (telephonyManager.getSimState() == telephonyManager.SIM_STATE_READY) {
Log.i(TAG, "良好");
} else if (telephonyManager.getSimState() == telephonyManager.SIM_STATE_ABSENT) {
Log.i(TAG, "无SIM卡");
} else {
Log.i(TAG, "SIM卡被锁定或未知的状态");
}
//获得sim卡的ISO国家代码
String simCountryString = telephonyManager.getSimCountryIso();
//获得sim卡的运营商代码
String simOperatorCode = telephonyManager.getSimOperator();
//获得sim卡运营商名称
String simOperatorName = telephonyManager.getSimOperatorName();
//获得sim的序列号
String simSerial = telephonyManager.getSimSerialNumber();
String phoneTypeStr = "unknown";
int phoneType = telephonyManager.getPhoneType();
switch (phoneType) {
case TelephonyManager.PHONE_TYPE_CDMA:
phoneTypeStr = "CDMA";
break;
case TelephonyManager.PHONE_TYPE_GSM:
phoneTypeStr = "GSM";
break;
case TelephonyManager.PHONE_TYPE_SIP:
phoneTypeStr = "SIP";
break;
case TelephonyManager.PHONE_TYPE_NONE:
phoneTypeStr = "None";
break;
default:
break;
}
Log.d(TAG, phoneTypeStr);
//读取GSM手机的IMEI或CDMA手机的MEID
String deviceId = telephonyManager.getDeviceId();
Log.d(TAG, deviceId);
//读取手机上的软件版本
String softwareVersion = telephonyManager.getDeviceSoftwareVersion();
Log.d(TAG, softwareVersion);
//获得手机号码
String phoneNumber = telephonyManager.getLine1Number();
}
private void getNetInfo(){
//获得连接网络所在国家的ISO代码
String netWorkCountry = telephonyManager.getNetworkCountryIso();
//获得连接网络的运营商MCC+MNC
String networkOperatorId = telephonyManager.getNetworkOperator();
//获得连接网络的运营商名称
String networkName = telephonyManager.getNetworkOperatorName();
//获得所连接网络的类型
int networkType = telephonyManager.getNetworkType();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.phone, menu);
return true;
}
}
没有找到相关结果
已邀请:
0 个回复