我想在祝酒词中显示哪个网络连接可用。但是当我启动我的应用程序时,它会向我显示布局,但它不会让我敬酒。我是不是忘记了什么?
// 现在我每秒显示一个 toast。它从正确的开始,然后转到下一个。我现在还有一个按钮,它在文本视图中显示网络类型。但它总是只显示4g ..提前感谢您的帮助!
Button start;
TextView ergebniss;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
start = (Button)findViewById(R.id.start);
start.setOnClickListener(this);
ergebniss = (TextView) findViewById(R.id.textView1);
}
public void getNetworkClass(Context context) {
TelephonyManager mTelephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
int networkType = mTelephonyManager.getNetworkType();
switch (networkType) {
case TelephonyManager.NETWORK_TYPE_GPRS:
case TelephonyManager.NETWORK_TYPE_EDGE:
case TelephonyManager.NETWORK_TYPE_CDMA:
case TelephonyManager.NETWORK_TYPE_1xRTT:
case TelephonyManager.NETWORK_TYPE_IDEN:
Toast.makeText(getApplicationContext(), "2G", Toast.LENGTH_LONG).show();
ergebniss.setText("2G");
case TelephonyManager.NETWORK_TYPE_UMTS:
case TelephonyManager.NETWORK_TYPE_EVDO_0:
case TelephonyManager.NETWORK_TYPE_EVDO_A:
case TelephonyManager.NETWORK_TYPE_HSDPA:
case TelephonyManager.NETWORK_TYPE_HSUPA:
case TelephonyManager.NETWORK_TYPE_HSPA:
case TelephonyManager.NETWORK_TYPE_EVDO_B:
case TelephonyManager.NETWORK_TYPE_EHRPD:
case TelephonyManager.NETWORK_TYPE_HSPAP:
Toast.makeText(getApplicationContext(), "3G", Toast.LENGTH_LONG).show();
ergebniss.setText("3G");
case TelephonyManager.NETWORK_TYPE_LTE:
Toast.makeText(getApplicationContext(), "4G", Toast.LENGTH_LONG).show();
ergebniss.setText("4G");
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
getNetworkClass(this);
}
}