2011-09-22 12 views

答えて

4

私が最近書いたapplilcationの別のスニペット:

TelephonyManager telManager;  
telManager = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE); 
int cType = telManager.getNetworkType(); 
String cTypeString; 
switch (cType) { 
     case 1: cTypeString = "GPRS"; break; 
     case 2: cTypeString = "EDGE"; break; 
     case 3: cTypeString = "UMTS"; break; 
     case 8: cTypeString = "HSDPA"; break; 
     case 9: cTypeString = "HSUPA"; break; 
     case 10:cTypeString = "HSPA"; break; 
     default:cTypeString = "unknown"; break; 
} 
0

これは、あなたがインターネット接続(3G)持っているかどうかをチェックします:

private boolean isNetworkAvailable() { 
    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); 
    NetworkInfo activeNetworkInfo = connectivityManager 
      .getActiveNetworkInfo(); 
    return activeNetworkInfo != null; 
} 
1
ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); 

    NetworkInfo mMobile = connManager 
      .getNetworkInfo(ConnectivityManager.TYPE_MOBILE); 

    if (mMobile.isAvailable() == true) { 
     Intent otherActivity = new Intent(); 
     mapActivity.setClass(getBaseContext(), other.class); 
     startActivity(otherActivity); 
    } 

を「ACCESS_NETWORK_STATE」権限を追加することを忘れないでください。 AndroidManifext.xmlファイルにあります。

2

は、最初のあなただけのあなたも、この

if (getSsTelephony().getNetworkType() >= TelephonyManager.NETWORK_TYPE_UMTS) 
    return NETWORK_3G; 
を行うことができますので、あなたがEDGEまたはGPRSまたは何かになり得ること

(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE)).getNetworkType()); 

ない呼び出すよりも、無線LANやモバイルネットワーク

があるかどうかを確認する必要があります

3

試してみてください。

void checkConnectionStatus() 
     { 
     ConnectivityManager connMgr = (ConnectivityManager) 
     this.getSystemService(Context.CONNECTIVITY_SERVICE); 


     final android.net.NetworkInfo wifi = 
     connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); 


     final android.net.NetworkInfo mobile = 
     connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); 


     if(wifi.isAvailable()){ 
     Toast.makeText(this, "Wifi" , Toast.LENGTH_LONG).show(); 
     } 
     else if(mobile.isAvailable()){ 
     Toast.makeText(this, "Mobile 3G " , Toast.LENGTH_LONG).show(); 
     } 
     else 
     {Toast.makeText(this, "No Network " , Toast.LENGTH_LONG).show();} 
     } 
} 
関連する問題