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

  • SEARCH
  • Home
  • 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 6865225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:00:55+00:00 2026-05-27T03:00:55+00:00

I’m developing an application in which the wifi state goes OFF when the phonestate

  • 0

I’m developing an application in which the wifi state goes OFF when the phonestate is RINGING.

My code is as follows :

phonestateManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.phone.state"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk android:minSdkVersion="8" />
    <application android:icon="@drawable/ic_launcher" >
        <activity
            android:label="@string/app_name"
            android:name=".PhonestateActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />    
                <category android:name="android.intent.category.LAUNCHER" />    
                <action android:name="android.intent.action.PHONE_STATE" />
            </intent-filter>
        </activity>    
        <activity android:name=".WifitoggleActivity" />    
        <receiver android:name=".ServiceReceiver" />
    </application>    
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />    
    <uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" />    
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />    
    <uses-permission android:name="android.permission.WAKE_LOCK" />    
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
</manifest>

PhonestateActivity.java

public class PhonestateActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button button1 = (Button) findViewById(R.id.button1);
        button1.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(PhonestateActivity.this,
                        ServiceReceiver.class);
                startActivity(intent);
            }
        });
    }
}

ServiceReceiver.java

public class ServiceReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        MyPhoneStateListener phoneListener = new MyPhoneStateListener();
        TelephonyManager telephony = (TelephonyManager);
        context.getSystemService(Context.TELEPHONY_SERVICE);
        telephony.listen(phoneListener, MyPhoneStateListener.LISTEN_CALL_STATE);
    }
}

MyPhoneStateListener.java

public class MyPhoneStateListener extends PhoneStateListener {
    @SuppressWarnings("unused")
    private WifitoggleActivity ss;

    public void onCallStateChanged(int state, String incomingNumber) {
        switch (state) {
            case TelephonyManager.CALL_STATE_IDLE:
            Log.d("DEBUG", "IDLE");
            break;
            case TelephonyManager.CALL_STATE_RINGING: {
            ss = new WifitoggleActivity();
            Log.d("DEBUG", "RINGING");
            break;
            }
        }
    }
}

WifitoggleActivity.java

public class WifitoggleActivity extends Activity {
    public WifitoggleActivity() {
        System.out.print("INSIDE WIFI");
    }

    /** Called when the activity is first created. */
    private WifiManager wifiManager;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // setContentView(R.layout.main);
        wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        if (wifiManager.isWifiEnabled()) {
            wifiManager.setWifiEnabled(false);
        } else {
            wifiManager.setWifiEnabled(true);
        }
    }
}

The code is just FORCE CLOSEing in my device. Is it a problem with the Manifest file?

Please help me to find a solution.

Thanks in advance guys.

  • 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-05-27T03:00:56+00:00Added an answer on May 27, 2026 at 3:00 am

    ServiceReceiver is a BroadcastReceiver not an Activity. You are using wrong code in first block.

    Find the onClick handler in your code:

    public class PhonestateActivity extends Activity {
    
         /** Called when the activity is first created. */   
         @Override
         public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          Button button1= (Button)findViewById(R.id.button1);
          button1.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
    

    Then remove these two lines:

            Intent intent = new Intent(PhonestateActivity.this,ServiceReceiver.class);
            startActivity(intent);
    

    and replace them by

            IntentFilter intentFilter=new IntentFilter(Intent.ACTION_ANSWER);
            registerReceiver(new ServiceReceiver(),intentFilter);
    

    As ServiceReceiver is not an activity.

    Edited

    Add one more permission:

     android.permission.PROCESS_OUTGOING_CALLS
    

    and change

      <receiver android:name=".ServiceReceiver">
       <intent-filter>
         <action android:name=" android.intent.action.PHONE_STATE" />  
       </intent-filter>
      </receiver>
    

    Now remove two line that registering broadcast from oncreate method
    Check this link

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
I'm parsing an XML file, the creators of it stuck in a bunch social
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.