Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7985681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:37:34+00:00 2026-06-04T11:37:34+00:00

When I run my app it crash out can anybody help me out and

  • 0

When I run my app it crash out can anybody help me out and guide me in the correct direction of making this code work?

public class DeviceInfoActivity extends Activity {

        private static final String APP_NAME = "SignalLevelSample";
        private static final int EXCELLENT_LEVEL = 75;
        private static final int GOOD_LEVEL = 50;
        private static final int MODERATE_LEVEL = 25;
        private static final int WEAK_LEVEL = 0;

        private static final int INFO_SERVICE_STATE_INDEX = 0;
        private static final int INFO_CELL_LOCATION_INDEX = 1;
        private static final int INFO_CALL_STATE_INDEX = 2;
        private static final int INFO_CONNECTION_STATE_INDEX = 3;
        private static final int INFO_SIGNAL_LEVEL_INDEX = 4;
        private static final int INFO_SIGNAL_LEVEL_INFO_INDEX = 5;
        private static final int INFO_DATA_DIRECTION_INDEX = 6;
        private static final int INFO_DEVICE_INFO_INDEX = 7;

        private static final int[] info_ids= {
                R.id.serviceState_info,
                R.id.cellLocation_info,
                R.id.callState_info,
                R.id.connectionState_info,
                R.id.signalLevel,
                R.id.signalLevelInfo,
                R.id.dataDirection,
                R.id.device_info
        };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        startSignalLevelListener();
        displayTelephonyInfo();
    }


    @Override
        protected void onPause()
        {
                super.onPause();

                stopListening();
        }

        @Override
        protected void onResume()
        {
                super.onResume();

                startSignalLevelListener();
        }

        @Override
        protected void onDestroy()
        {
                stopListening();

                super.onDestroy();
        }

        private void setTextViewText(int id,String text) {
                ((TextView)findViewById(id)).setText(text);
        }

        private void setSignalLevel(int id,int infoid,int level){
                int progress = (int) ((((float)level)/31.0) * 100);
                String signalLevelString = getSignalLevelString(progress);

                ((ProgressBar)findViewById(id)).setProgress(progress);
                ((TextView)findViewById(infoid)).setText(signalLevelString);

                Log.i("signalLevel ","" + progress);
        }

        private String getSignalLevelString(int level) {
                String signalLevelString = "Weak";

                if(level > EXCELLENT_LEVEL)             signalLevelString = "Excellent";
                else if(level > GOOD_LEVEL)             signalLevelString = "Good";
                else if(level > MODERATE_LEVEL) signalLevelString = "Moderate";
                else if(level > WEAK_LEVEL)             signalLevelString = "Weak";

                return signalLevelString;
        }

        private void stopListening(){
                TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);

                tm.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
        }

        private void setDataDirection(int id, int direction){
                int resid = getDataDirectionRes(direction);

                ((ImageView)findViewById(id)).setImageResource(resid);
        }

        private int getDataDirectionRes(int direction){
                int resid = R.drawable.ic_launcher;

                switch(direction)
                {
                        case TelephonyManager.DATA_ACTIVITY_IN:         resid = R.drawable.ic_launcher; break;
                        case TelephonyManager.DATA_ACTIVITY_OUT:        resid = R.drawable.ic_launcher; break;
                        case TelephonyManager.DATA_ACTIVITY_INOUT:      resid = R.drawable.ic_launcher; break;
                        case TelephonyManager.DATA_ACTIVITY_NONE:       resid = R.drawable.ic_launcher; break;
                        default:                                        resid = R.drawable.ic_launcher; break;
                }

                return resid;
        }

        private void startSignalLevelListener() {
        TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        int events = PhoneStateListener.LISTEN_SIGNAL_STRENGTH | 
                                 PhoneStateListener.LISTEN_DATA_ACTIVITY | 
                                 PhoneStateListener.LISTEN_CELL_LOCATION |
                                 PhoneStateListener.LISTEN_CALL_STATE |
                                 PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
                                 PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
                                 PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
                                 PhoneStateListener.LISTEN_SERVICE_STATE;

        tm.listen(phoneStateListener, events);
    }

        private void displayTelephonyInfo(){
                TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
                GsmCellLocation loc = (GsmCellLocation) tm.getCellLocation();

                int cellid = loc.getCid();
                int lac = loc.getLac();

                String deviceid = tm.getDeviceId();
                String phonenumber = tm.getLine1Number();
                String softwareversion = tm.getDeviceSoftwareVersion();
                String operatorname = tm.getNetworkOperatorName();
                String simcountrycode = tm.getSimCountryIso();
                String simoperator = tm.getSimOperatorName();
                String simserialno = tm.getSimSerialNumber();
                String subscriberid = tm.getSubscriberId();
                String networktype = getNetworkTypeString(tm.getNetworkType());
                String phonetype = getPhoneTypeString(tm.getPhoneType());

                logString("CellID: " + cellid);
                logString("LAC: " + lac);
                logString("Device ID: " + deviceid);
                logString("Phone Number: " + phonenumber);
                logString("Software Version: " + softwareversion);
                logString("Operator Name: " + operatorname);
                logString("SIM Country Code: " + simcountrycode);
                logString("SIM Operator: " + simoperator);
                logString("SIM Serial No.: " + simserialno);
                logString("Sibscriber ID: " + subscriberid);

                String deviceinfo = "";

                deviceinfo += ("CellID: " + cellid + "\n");
                deviceinfo += ("LAC: " + lac + "\n");
                deviceinfo += ("Device ID: " + deviceid + "\n");
                deviceinfo += ("Phone Number: " + phonenumber + "\n");
                deviceinfo += ("Software Version: " + softwareversion + "\n");
                deviceinfo += ("Operator Name: " + operatorname + "\n");
                deviceinfo += ("SIM Country Code: " + simcountrycode + "\n");
                deviceinfo += ("SIM Operator: " + simoperator + "\n");
                deviceinfo += ("SIM Serial No.: " + simserialno + "\n");
                deviceinfo += ("Subscriber ID: " + subscriberid + "\n");
                deviceinfo += ("Network Type: " + networktype + "\n");
                deviceinfo += ("Phone Type: " + phonetype + "\n");

                List<NeighboringCellInfo> cellinfo = tm.getNeighboringCellInfo();

                if(null != cellinfo){
                        for(NeighboringCellInfo info: cellinfo){
                                deviceinfo += ("\tCellID: " + info.getCid() + ", RSSI: " + info.getRssi() + "\n");
                        }
                }

                setTextViewText(info_ids[INFO_DEVICE_INFO_INDEX],deviceinfo);
        }

        private String getNetworkTypeString(int type){
                String typeString = "Unknown";

                switch(type)
                {
                        case TelephonyManager.NETWORK_TYPE_EDGE:        typeString = "EDGE"; break;
                        case TelephonyManager.NETWORK_TYPE_GPRS:        typeString = "GPRS"; break;
                        case TelephonyManager.NETWORK_TYPE_UMTS:        typeString = "UMTS"; break;
                        default:                                                                        typeString = "UNKNOWN"; break;
                }

                return typeString;
        }

        private String getPhoneTypeString(int type){
                String typeString = "Unknown";

                switch(type)
                {
                        case TelephonyManager.PHONE_TYPE_GSM:   typeString = "GSM"; break;
                        case TelephonyManager.PHONE_TYPE_NONE:  typeString = "UNKNOWN"; break;
                        default:                                                                typeString = "UNKNOWN"; break;
                }

                return typeString;
        }

        private int logString(String message) {
                return Log.i(APP_NAME,message);
        }

    private final PhoneStateListener phoneStateListener = new PhoneStateListener(){

                @Override
                public void onCallForwardingIndicatorChanged(boolean cfi)
                {
                        Log.i(APP_NAME, "onCallForwardingIndicatorChanged " + cfi);

                        super.onCallForwardingIndicatorChanged(cfi);
                }

                @Override
                public void onCallStateChanged(int state, String incomingNumber)
                {
                        String callState = "UNKNOWN";

                        switch(state)
                        {
                                case TelephonyManager.CALL_STATE_IDLE:          callState = "IDLE"; break;
                                case TelephonyManager.CALL_STATE_RINGING:       callState = "Ringing (" + incomingNumber + ")"; break;
                                case TelephonyManager.CALL_STATE_OFFHOOK:       callState = "Offhook"; break;
                        }

                        setTextViewText(info_ids[INFO_CALL_STATE_INDEX],callState);

                        Log.i(APP_NAME, "onCallStateChanged " + callState);

                        super.onCallStateChanged(state, incomingNumber);
                }

                @Override
                public void onCellLocationChanged(CellLocation location)
                {
                        String locationString = location.toString();

                        setTextViewText(info_ids[INFO_CELL_LOCATION_INDEX],locationString);

                        Log.i(APP_NAME, "onCellLocationChanged " + locationString);

                        super.onCellLocationChanged(location);
                }

                @Override
                public void onDataActivity(int direction)
                {
                        String directionString = "none";

                        switch(direction)
                        {
                                case TelephonyManager.DATA_ACTIVITY_IN:         directionString = "IN"; break;
                                case TelephonyManager.DATA_ACTIVITY_OUT:        directionString = "OUT"; break;
                                case TelephonyManager.DATA_ACTIVITY_INOUT:      directionString = "INOUT"; break;
                                case TelephonyManager.DATA_ACTIVITY_NONE:       directionString = "NONE"; break;
                                default:                                                                        directionString = "UNKNOWN: " + direction; break;
                        }

                        setDataDirection(info_ids[INFO_DATA_DIRECTION_INDEX],direction);

                        Log.i(APP_NAME, "onDataActivity " + directionString);

                        super.onDataActivity(direction);
                }

                @Override
                public void onDataConnectionStateChanged(int state)
                {
                        String connectionState = "Unknown";

                        switch(state)
                        {
                                case TelephonyManager.DATA_CONNECTED:           connectionState = "Connected"; break;
                                case TelephonyManager.DATA_CONNECTING:          connectionState = "Connecting"; break;
                                case TelephonyManager.DATA_DISCONNECTED:        connectionState = "Disconnected"; break;
                                case TelephonyManager.DATA_SUSPENDED:           connectionState = "Suspended"; break;
                                default:                                                                        connectionState = "Unknown: " + state; break;
                        }

                        setTextViewText(info_ids[INFO_CONNECTION_STATE_INDEX],connectionState);

                        Log.i(APP_NAME, "onDataConnectionStateChanged " + connectionState);

                        super.onDataConnectionStateChanged(state);
                }

                @Override
                public void onMessageWaitingIndicatorChanged(boolean mwi)
                {
                        Log.i(APP_NAME, "onMessageWaitingIndicatorChanged " + mwi);

                        super.onMessageWaitingIndicatorChanged(mwi);
                }

                @Override
                public void onServiceStateChanged(ServiceState serviceState)
                {
                        String serviceStateString = "UNKNOWN";

                        switch(serviceState.getState())
                        {
                                case ServiceState.STATE_IN_SERVICE:             serviceStateString = "IN SERVICE"; break;
                                case ServiceState.STATE_EMERGENCY_ONLY:         serviceStateString = "EMERGENCY ONLY"; break;
                                case ServiceState.STATE_OUT_OF_SERVICE:         serviceStateString = "OUT OF SERVICE"; break;
                                case ServiceState.STATE_POWER_OFF:                      serviceStateString = "POWER OFF"; break;
                                default:                                                                        serviceStateString = "UNKNOWN"; break;
                        }

                        setTextViewText(info_ids[INFO_SERVICE_STATE_INDEX],serviceStateString);

                        Log.i(APP_NAME, "onServiceStateChanged " + serviceStateString);

                        super.onServiceStateChanged(serviceState);
                }

                @Override
                public void onSignalStrengthChanged(int asu)
                {
                        Log.i(APP_NAME, "onSignalStrengthChanged " + asu);

                        setSignalLevel(info_ids[INFO_SIGNAL_LEVEL_INDEX],info_ids[INFO_SIGNAL_LEVEL_INFO_INDEX],asu);

                        super.onSignalStrengthChanged(asu);
                }
    };
}

//========================
xml

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:scrollbarStyle="insideOverlay"
        android:scrollbarAlwaysDrawVerticalTrack="false">

        <LinearLayout 
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">


                <LinearLayout
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal">

                        <TextView android:text="Serivice State" style="@style/labelStyleRight"/>
                        <TextView android:id="@+id/serviceState_info" style="@style/textStyle"/>
                </LinearLayout>

                <LinearLayout
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal">

                        <TextView android:text="Cell Location" style="@style/labelStyleRight"/>
                        <TextView android:id="@+id/cellLocation_info" style="@style/textStyle"/>
                </LinearLayout>

                <LinearLayout
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal">

                        <TextView android:text="Call State" style="@style/labelStyleRight"/>
                        <TextView android:id="@+id/callState_info" style="@style/textStyle"/>
                </LinearLayout>

                <LinearLayout
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal">

                        <TextView android:text="Connection State" style="@style/labelStyleRight"/>
                        <TextView android:id="@+id/connectionState_info" style="@style/textStyle"/>
                </LinearLayout>

                <LinearLayout
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal">

                        <TextView android:text="Signal Level" style="@style/labelStyleRight"/>

                        <LinearLayout
                                android:layout_width="fill_parent"
                                android:layout_height="wrap_content"
                                android:layout_weight="0.5"
                                android:orientation="horizontal">

                                <ProgressBar android:id="@+id/signalLevel" style="@style/progressStyle"/>
                                <TextView android:id="@+id/signalLevelInfo" style="@style/textSmallStyle"/>
                        </LinearLayout>
                </LinearLayout>

                <LinearLayout
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal">

                        <TextView android:text="Data" style="@style/labelStyleRight"/>
                        <ImageView android:id="@+id/dataDirection" style="@style/imageStyle"/>
                </LinearLayout>

                <TextView android:id="@+id/device_info" style="@style/labelStyleLeft"/>
        </LinearLayout>
</ScrollView>

//=================

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="sirisak.phone"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk android:minSdkVersion="8" />
    <application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
        <activity android:name=".DeviceInfoActivity "
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
        <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"></uses-permission>
        <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
        <uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES"></uses-permission>
</manifest> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:37:35+00:00Added an answer on June 4, 2026 at 11:37 am

    You need to add:

    android:name="android.app.Application"
    

    to the application tag in AndroidManifest.xml.

    This is because you have a ClassCastException. See: android classcastexception on activity startup

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

maybe you can help me out. I'm working on an Android app project that
I hope someone can help me out with this. I can't reproduce this error
The app will run fine, then crash - literally every other time. It seems
Just wondering if anybody has run Scala app or web-app on Java Real-Time system?
Having this errors when trying to compile/run my app using Maven. I've succeeded to
What's incorrect in this manifest to run an app as Admin? It works fine
I can't figure out what is causing this. Basically, a few different 'tasks' are
when i run app in the IPhone simulater 5.1 the default image loads up
I'm testing my application as grails run-app. I have read How to remove app
I am trying to run our App on Mac Lion. App is built on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.