networking - Display the network connection 2g/3g or 4g in a toast -
i display in toast network connection available. when start app shows me layout, doesn't make toast. did forget something?
// shows every second toast. beginns right 1 goes next one.. have button now, shows me networktyp in textview. show 4g.. in advance help!
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); }
}
you need @ least show toast.
toast.maketext(getapplicationcontext(), "2g", toast.length_long).show();
and you're missing break;
(or return ..) statement after toast.maketext()
calls.
Comments
Post a Comment