getNetworkOperator() keeps crashing in airplane mode

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

getNetworkOperator() keeps crashing in airplane mode

Postby the_Inquisitor » Tue Mar 02, 2010 1:25 pm

Hello World,

I'm a newbie to Java and Android writing an app, that should get network info on startup. I've written the following code, however if the phone is in airplane mode, it keeps crashing allthough I use a try/catch-statement:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class HelloAndroid extends Activity {
  2.  
  3.    @Override
  4.  
  5.    public void onCreate(Bundle savedInstanceState) {
  6.  
  7.        super.onCreate(savedInstanceState);
  8.  
  9.  
  10.  
  11.        TelephonyManager tel = (TelephonyManager)
  12.  
  13.        getSystemService(Context.TELEPHONY_SERVICE);
  14.  
  15.            String imsi = "000000000000000";
  16.  
  17.            String networkOperator = "00000";
  18.  
  19.  
  20.  
  21.                try {
  22.  
  23.                            imsi = tel.getSubscriberId();
  24.  
  25.                            networkOperator = tel.getNetworkOperator();
  26.  
  27.                } catch (Exception e) {
  28.  
  29.                        alert("Exception",e+"");
  30.  
  31.                }
  32.  
  33.  
  34.  
  35.    }
  36.  
  37.  
  38.  
  39.                private void alert(String alerttitle, String alertmessage) {
  40.  
  41.                AlertDialog alertDialog = new
  42.  
  43.                AlertDialog.Builder(this).create();
  44.  
  45.                alertDialog.setTitle(alerttitle);
  46.  
  47.                alertDialog.setMessage(alertmessage);
  48.  
  49.                    alertDialog.setButton("OK", new
  50.  
  51.                    DialogInterface.OnClickListener() {
  52.  
  53.                          public void onClick(DialogInterface dialog, int which) {
  54.  
  55.                            return;
  56.  
  57.                          } });
  58.  
  59.                    alertDialog.show();
  60.  
  61.                }
  62.  
  63.    }
  64.  
  65.  
Parsed in 0.012 seconds, using GeSHi 1.0.8.4



I have also tried isNetworkAvailable method described at
http://www.androidsnippets.org/snippets/78/ but it crashes in airplane
mode, too.

Any hints on how to solve this?

Thanks for any help in advance!
the_Inquisitor
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Mar 02, 2010 12:59 pm

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 4 guests