package com.dingchao.phonemanagerutil;
import java.util.ArrayList;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class TelephonyManagerActivity extends Activity {
private ListView listView=null;
private TelephonyManager tm=null;
private String[] phoneType=null;
private String[] simState=null;
private String[] listItems=null;
ArrayList<String> listValues=new ArrayList<String>();
BaseAdapter adapter=new BaseAdapter(){
public int getCount() {
return listItems.length;
}
public Object getItem(int position) {
return listItems[position];
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout ll=new LinearLayout(TelephonyManagerActivity.this);
ll.setOrientation(LinearLayout.HORIZONTAL);
TextView tvItem=new TextView(TelephonyManagerActivity.this);
tvItem.setTextSize(15);
tvItem.setText(listItems[position]+":");
tvItem.setGravity(Gravity.LEFT);//设置在父容器中的对齐方式
ll.addView(tvItem);
TextView tvValue=new TextView(TelephonyManagerActivity.this);
tvValue.setTextSize(15); //设置字体大小
tvValue.setText(listValues.get(position)); //设置显示的内容
tvValue.setPadding(0, 0, 10, 10); //设置四周边界
tvValue.setGravity(Gravity.RIGHT);
ll.addView(tvValue);
return ll;
}
};
/**
* @author 丁超
* @return 该SIM卡是否支持
*/
private boolean isSupportSIM()
{
boolean isSupportSIM = false;
TelephonyManager tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
if(tm.getNetworkOperator().equals("46000")
||(tm.getNetworkOperator().equals("46002"))
)
{
isSupportSIM = true;
}
return isSupportSIM;
}
@Override
public void onCreate(Bundle savedInstanceState) {
/*
* 锁卡功能
* add by dingchao 2013.10.24
*/
if(!isSupportSIM())
{
Builder dialog = new AlertDialog.Builder(this);
dialog.setMessage(R.string.hello_world);
dialog.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if(keyCode == KeyEvent.KEYCODE_BACK)
{
TelephonyManagerActivity.this.finish();
return true;
}
return false;
}
});
dialog.setPositiveButton(R.string.hello_world, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
TelephonyManagerActivity.this.finish();
}
});
dialog.show();
Toast.makeText(this, "is not support", Toast.LENGTH_LONG).show();
}
super.onCreate(savedInstanceState);
//Toast.makeText(getApplicationContext(), "is not support", Toast.LENGTH_LONG).show();
setContentView(R.layout.activity_main);
listItems=getResources().getStringArray(R.array.listItem);
simState=getResources().getStringArray(R.array.simState);
phoneType=getResources().getStringArray(R.array.phoneType);
tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
listView=(ListView)findViewById(R.id.listView);
initListValues();
listView.setAdapter(adapter);
}
/**
* 获取各个数据项的值
*/
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());//获取设备当前位置
}
}
Android通过MCC+MNC实现锁卡
最新推荐文章于 2022-04-27 23:52:24 发布