android - Sometimes telephone sim operator and name are empty, why? -


i try send network state server.

i check network type wifi or cellular , if secular send sim operator name , network operator name.

here go:

private string getnetworktype(context context){     connectivitymanager cm = (connectivitymanager) context.getsystemservice(context.connectivity_service);     networkinfo activenetwork = cm.getactivenetworkinfo();     if (activenetwork != null) { // connected internet         if (activenetwork.gettype() == connectivitymanager.type_wifi) {             // connected wifi             return "wifi";         } else if (activenetwork.gettype() == connectivitymanager.type_mobile) {             // connected mobile provider's data plan             return "mobile";         }     } else {         // not connected internet     }     return "unknown"; }  

and:

try {         final string networktype = getnetworktype(context);         if ("mobile".equals(networktype)) {             params.put("wifi",false);             try {                 final telephonymanager manager = (telephonymanager) context.getsystemservice(context.telephony_service);                 params.put("operator",manager.getsimoperatorname());                 params.put("carrier",manager.getnetworkoperatorname());             } catch (throwable e){                 aflogger.aferrorlog("exception while collecting network operator/carrier.",e);             }         }         else{           params.put("wifi",true);         }     } catch (throwable e){         //...     }  

the problem is:

in 5% of requests (from ~10000) comes with:

{   "wifi":"false",   "operator": "",    "carrier": "" } 

it happens on random device brands: samsung, google, lge, htc, oppo ....

do miss in code?

why manager.getsimoperatorname() returns empty string?

if request - means device sent on internet , therefore if wifi false - device sends on cell.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -