嗨我正在使用模拟器测试应用程序但是当我运行应用程序时,它仍然显示gprs可用任何想法为什么?在模拟器中没有gprs然后为什么它的显示gprs可用?什么是ConnectivityManager.TYPE_MOBILE是什么意思?只意味着gprs ??
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp.setAdapter(adapter);
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int position, long
id) {
if (position == 0)
{
final ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
android.net.NetworkInfo mobile =
connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if( mobile.isAvailable() ){
Toast.makeText(LoginScreen.this, " GPRS Connection Found "
, Toast.LENGTH_LONG).show();
}
else if( !mobile.isAvailable() ){
Toast.makeText(LoginScreen.this, "No GPRS
Connection Found " , Toast.LENGTH_LONG).show();
}
}
if (position == 1)
{
final ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
final android.net.NetworkInfo wifi =
connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if( wifi.isAvailable() ){
Toast.makeText(LoginScreen.this, " Wifi Found" ,
Toast.LENGTH_LONG).show();
}
else if( !wifi.isAvailable() ){
Toast.makeText(LoginScreen.this, "No Wifi found " ,
Toast.LENGTH_LONG).show();
}
}
if (position == 3)
{
final ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
BluetoothAdapter mBluetoothAdapter =
BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter.isEnabled()) {
Toast.makeText(LoginScreen.this, " BlueTooth Found" ,
Toast.LENGTH_LONG).show();
}else if( !mBluetoothAdapter.isEnabled() ){
Toast.makeText(LoginScreen.this, "No BlueTooth found "
, Toast.LENGTH_LONG).show();
}
}
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
答案 0 :(得分:0)
ConnectionManager
不会检查所提供类型(TYPE_MOBILE
)的类型。它只报告无论基础协议如何都存在数据连接。
NetworkInfo.getSubTypeName()将拥有网络的子类型。
同样问题的this现有答案。