打电话其实就是跳转到一个activity:
Intent intent=new Intent("android.intent.action.CALL",Uri.parse("tel:"+电话号码));
startActivity(intent);
权限: <uses-permission android:name="android.permission.CALL_PHONE" ></uses-permission>
TelephonyManager类:
package com.andriod.test.phone;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
public class TelephonyManagerActivity extends Activity
{
private ListView listView;
private TelephonyManager tm = null;
private String[] phoneType = null;
private String[] simState = null;
private String[] listItems = null;
ArrayList<String> listValues=new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.telephony);
listItems=getResources().getStringArray(R.array.listItem);
simState=getResources().getStringArray(R.array.simState);
phoneType=getResources().getStringArray(R.array.phoneType);
listView=(ListView)findViewById(R.id.listView);
tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
initListValues();
listView.setAdapter(baseAdapter);
}
private BaseAdapter baseAdapter=new BaseAdapter() {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout ll = new LinearLayout(TelephonyManagerActivity.this);
ll.setOrientation(LinearLayout.VERTICAL);
TextView tvItem = new TextView(TelephonyManagerActivity.this);
tvItem.setTextSize(24);
tvItem.setText(listItems[position]);
tvItem.setGravity(Gravity.CENTER);
ll.addView(tvItem);
TextView tvValue = new TextView(TelephonyManagerActivity.this);
tvValue.setTextSize(18); // 设置字体大小
tvValue.setText(listValues.get(position)); // 设置显示的内容
tvValue.setPadding(0, 0, 10, 10); // 设置四周边界
tvValue.setGravity(Gravity.RIGHT);
ll.addView(tvValue);
return ll;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public Object getItem(int position) {
return listItems[position];
}
@Override
public int getCount() {
return listItems.length;
}
};
public void initListValues(){
listValues.add(tm.getDeviceId());//获取设备编号
listValues.add(tm.getSimCountryIso());//获取SIM卡国别
listValues.add(tm.getSimSerialNumber());//获取SIM卡序列号
listValues.add(simState[tm.getSimState()]);//获取SIM卡状态
listValues.add((tm.getDeviceSoftwareVersion()!=null?tm.getDeviceSoftwareVersion():"未知")); //获取软件版本
listValues.add(tm.getNetworkOperator());//获取网络运营商代号
listValues.add(tm.getNetworkOperatorName());//获取网络运营商名称
listValues.add(phoneType[tm.getPhoneType()]);//获取手机制式
// listValues.add(tm.getCellLocation().toString());//获取设备当前位置
listValues.add("");
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="listItem">
<item>设备编号</item>
<item>SIM卡国别</item>
<item>SIM卡序列号</item>
<item>SIM卡状态</item>
<item>软件版本</item>
<item>网络运营商代号</item>
<item>网络运营商名称</item>
<item>手机制式</item>
<item>设备当前位置</item>
</string-array>
<string-array name="simState">
<item>状态未知</item>
<item>无SIM卡</item>
<item>被PIN加锁</item>
<item>被PUK加锁</item>
<item>被NetWork PIN加锁</item>
<item>已准备好</item>
</string-array>
<string-array name="phoneType">
<item>未知</item>
<item>GSM</item>
<item>CDMA</item>
</string-array>
</resources>