Check TelephonyManager.listen() method.

Syntax : void
android.telephony.TelephonyManager.listen(PhoneStateListener listener,
int events)

You have to include a class extending PhoneStateListener and try
networkOperator = tel.getNetworkOperator();   inside that.

Regards,
SREEHARI


On Mar 1, 10:11 pm, Inquisitor <christian.von.der.r...@googlemail.com>
wrote:
> 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 
> athttp://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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to