Hello World,

I'm 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:



public class HelloAndroid extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TelephonyManager tel = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
            String imsi = "000000000000000";
            String networkOperator = "00000";

                try {
                            imsi = tel.getSubscriberId();
                            networkOperator = tel.getNetworkOperator();
                } catch (Exception e) {
                        alert("Exception",e+"");
                }

    }

                private void alert(String alerttitle, String alertmessage) {
                AlertDialog alertDialog = new
AlertDialog.Builder(this).create();
                alertDialog.setTitle(alerttitle);
                alertDialog.setMessage(alertmessage);
                    alertDialog.setButton("OK", new
DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int 
which) {
                            return;
                          } });
                    alertDialog.show();
                }
    }



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!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to