ITeye博客

Check Network Type with TelephonyManager

helpbs · 2011-12-26 17:26 · Markdown

//packageuk.me.kjs.android.helloworld;

importandroid.app.Activity;
importandroid.app.Notification;
importandroid.app.NotificationManager;
importandroid.app.PendingIntent;
importandroid.content.Context;
importandroid.content.Intent;
importandroid.telephony.*;
importandroid.os.Bundle;
importandroid.widget.TextView;
importandroid.widget.Toast;

publicclassInitextendsActivity{
/**Calledwhentheactivityisfirstcreated.*/
@Override
public****voidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
TextViewtv=newTextView(this);
TelephonyManagertm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
Stringstr=newString();
Stringnet=newString();

switch(tm.getNetworkType())
{
caseTelephonyManager.NETWORK_TYPE_1xRTT:
net="CDMA-2000";
break;
caseTelephonyManager.NETWORK_TYPE_CDMA:
net="CDMA";
break;
caseTelephonyManager.NETWORK_TYPE_EDGE:
net="GSM-EDGE";
break;
caseTelephonyManager.NETWORK_TYPE_EVDO_0:
net="CDMA-EVDOA";
break;
caseTelephonyManager.NETWORK_TYPE_EVDO_A:
net="CDMA-EVDOA";
break;
caseTelephonyManager.NETWORK_TYPE_GPRS:
net="GSM-GPRS";
break;
caseTelephonyManager.NETWORK_TYPE_UMTS:
net="UMTS";
break;
case8:
net="UMTS-HSDPA";
break;
case9:
net="UMTS-HSUPA";
break;
case10:
net="UMTS-HSPA";
break;
caseTelephonyManager.NETWORK_TYPE_UNKNOWN:
default:
net="Unknown";
}

Stringhome=newString();
if(tm.isNetworkRoaming()==true)
{
home="Roaming";
}
else
{
home="Home";
}

str="SIMInformation";
str+="\nName:"+tm.getSimOperatorName();
str+="\nCode:"+tm.getSimOperator()+"("+tm.getSimCountryIso()+")";
str+="\n";
str+="\nConnectedNetwork";
str+="\nName:"+tm.getNetworkOperatorName();
str+="\nRoaming:"+home;
str+="\nCode:"+tm.getNetworkOperator()+"("+tm.getNetworkCountryIso()+")";
str+="\nType:"+net;

tv.setTextSize(20);
tv.setText(str);
setContentView(tv);

Contextcontext=getApplicationContext();
CharSequencetext="Hellotoast!";
intduration=Toast.LENGTH_SHORT;

Toasttoast=Toast.makeText(context,text,duration);
toast.show();

}
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。