开发者

Need to shut off a service when a call is coming in and when user dials a number

开发者 https://www.devze.com 2023-03-03 11:09 出处:网络
So, I have a service that runs in the background (it\'s super secret so I cant tell you what it is:) ) but I need to be able to shut it off when the user initiates a call or a call is coming in. So fa

So, I have a service that runs in the background (it's super secret so I cant tell you what it is:) ) but I need to be able to shut it off when the user initiates a call or a call is coming in. So far, I have checked out the Intent.ACTION_ANSWER, but for some reason, my Broadcast receiver never detects it. I have also tried to use the PhoneStateListener, but in my case statements, I am failing to understand how to do anything with my service. To what context is a PhoneStateListener?

Some example code for my BroadcastReceiver:

public void onReceive(Context context, Intent intent) {     
if (intent.getAction().equals(Intent.ACTION_ANSWER)) {
        phoneRinging = true;   开发者_JS百科         
    }

Intent i = new Intent(context, MyService.class);        
    i.putExtra("phone", phoneRinging);
    context.startService(i);
}

Here is a snippet for starting a service via the PhoneStateListener. Example: startService(new Intent(---CONTEXT---, MySuperSecretService.class))

And the receiver is in the manifest:

<receiver android:name=".PhoneReceiver" android:enabled="true">
    <intent-filter>
        <action android:name="android.intent.action.ANSWER"></action>
    </intent-filter>
</receiver>

WTH goes into the CONTEXT portion in this statement if I am in a PhoneStateListener?


Please check ACTION_PHONE_STATE_CHANGED instead of ACTION_ANSWER. ACTION_ANSWER is not broadcast intent for incoming call. It's a standard activity action.

0

精彩评论

暂无评论...
验证码 换一张
取 消