当我打电话时,我希望从后台服务启动一项活动。 我可以在我打电话的时候开始活动,电话是我的头脑(与接近传感器有关的事情我认为)
但是当接近传感器检测到某些东西并且我尝试启动激活时,会调用该活动的onStart,然后直接调用onStop。
有人知道如何在通话中启动活动并且接近传感器会检测到某些内容吗?
01-02 15:42:14.829: I/KeepAliveService(5985): show pager call from Service
01-02 15:42:14.849: I/ActivityManager(167): Starting: Intent { flg=0x14050004 cmp=com.clb.clbmobile/.NewMessage (has extras) } from pid 5985
01-02 15:42:14.849: W/ActivityManager(167): Trying to launch com.clb.clbmobile/.NewMessage
01-02 15:42:14.859: D/KeyguardViewMediator(167): adjustUserActivityLocked mShowing: false mHidden: false
01-02 15:42:14.859: D/PowerManagerService(167): enableUserActivity true
01-02 15:42:14.859: D/StatusBarManagerService(167): manageDisableList what=0x0 pkg=android
01-02 15:42:14.859: D/InCallScreen(242): onWindowFocusChanged(false)...
01-02 15:42:14.859: D/InCallScreen(242): - onWindowFocusChanged: faking onDialerKeyUp()...
01-02 15:42:14.859: D/DTMFTwelveKeyDialer(242): Notifying dtmf key up.
01-02 15:42:14.889: I/KeepAliveService(5985): activity started
01-02 15:42:14.939: I/ClbActivity(5985): getting shared prefs
01-02 15:42:14.939: I/ClbActivity(5985): end shared prefs
01-02 15:42:14.939: I/AlertDialog(5985): Starting Alert Dialog
01-02 15:42:15.019: I/AlertDialog(5985): Done with init
01-02 15:42:15.079: D/BatteryService(167): update start
01-02 15:42:15.079: D/BatteryService(167): update start
01-02 15:42:15.079: D/BatteryService(167): update start
01-02 15:42:15.099: E/PlayerDriver(95): Creating Non-Tunnel mode playback - uncompressed MIO
01-02 15:42:15.099: W/MediaPlayer(5985): info/warning (1, 44)
01-02 15:42:15.109: I/AlertDialog(5985): Current volume = 15
01-02 15:42:15.109: E/MediaPlayer(5985): prepareAsync called in state 8
01-02 15:42:15.109: I/AlertDialog(5985): cant prepare Media Player
01-02 15:42:15.109: V/AudioPolicyManager(95): startOutput() output 1, stream 3, session 241
01-02 15:42:15.109: V/AudioPolicyManager(95): getDeviceForStrategy() from cache strategy 1, device 1
01-02 15:42:15.109: V/AudioPolicyManager(95): getNewDevice() selected device 1
01-02 15:42:15.109: V/AudioPolicyManager(95): setOutputDevice() output 1 device 1 delayMs 0
01-02 15:42:15.109: V/AudioPolicyManager(95): setOutputDevice() setting same device 1 or null device for output 1
01-02 15:42:15.109: V/AudioHardwareMSM72XX(95): open driver
01-02 15:42:15.109: V/AudioHardwareMSM72XX(95): get config
01-02 15:42:15.109: V/AudioHardwareMSM72XX(95): set config
01-02 15:42:15.109: V/AudioHardwareMSM72XX(95): buffer_size: 4800
01-02 15:42:15.109: V/AudioHardwareMSM72XX(95): buffer_count: 2
01-02 15:42:15.109: V/AudioHardwareMSM72XX(95): channel_count: 2
01-02 15:42:15.109: V/AudioHardwareMSM72XX(95): sample_rate: 44100
01-02 15:42:15.109: V/AudioHardwareMSM72XX(95): count : 4800
01-02 15:42:15.139: I/AlertDialog(5985): start pausing
01-02 15:42:15.149: I/MediaPlayer(5985): Info (1,44)
01-02 15:42:15.369: I/ActivityManager(167): Displayed com.clb.clbmobile/.NewMessage: +517ms
01-02 15:42:15.489: W/IInputConnectionWrapper(5985): showStatusIcon on inactive InputConnection
01-02 15:42:15.489: W/IInputConnectionWrapper(5985): getExtractedText on inactive InputConnection
01-02 15:42:15.499: D/InCallScreen(242): onStop()...
01-02 15:42:15.499: D/InCallScreen(242): onStop: state = OFFHOOK
01-02 15:42:15.509: D/InCallScreen(242): onResume()...
01-02 15:42:15.519: D/PhoneApp(242): setIgnoreTouchUserActivity(true)...
01-02 15:42:15.519: D/DTMFTwelveKeyDialer(242): startDialerSession()... this = com.android.phone.DTMFTwelveKeyDialer@4055e2a0
01-02 15:42:15.519: D/DTMFTwelveKeyDialer(242): - startDialerSession: mDTMFToneEnabled = true
01-02 15:42:15.519: D/InCallScreen(242): - onResume: initial status = SUCCESS
01-02 15:42:15.519: D/InCallScreen(242): isBluetoothAudioConnected: ==> isAudioOn = false
01-02 15:42:15.519: D/InCallScreen(242): setInCallScreenMode: NORMAL
01-02 15:42:15.519: D/InCallScreen(242): [okToDialDTMFTones] foreground state: ACTIVE, ringing state: false, call screen mode: NORMAL, result: true
01-02 15:42:15.519: D/InCallScreen(242): isBluetoothAudioConnected: ==> isAudioOn = false
01-02 15:42:15.519: D/StatusBarManagerService(167): manageDisableList what=0x1 pkg=com.android.phone
01-02 15:42:15.519: D/PowerManagerService(167): setPokeLock pokey=16 tag=PhoneApp
01-02 15:42:15.519: D/PowerManagerService(167): setScreenOffTimeouts mKeylightDelay=3000 mDimDelay=7000 mScreenOffDelay=20000 mDimScreen=true
01-02 15:42:15.519: D/StatusBarManagerService(167): manageDisableList what=0x1 pkg=com.android.phone
01-02 15:42:15.519: I/CallOnGoingView(229): onDetachedFromWindow
01-02 15:42:15.669: D/InCallScreen(242): Handler: handling message { what=101 when=-48ms obj=android.os.AsyncResult@406d01b8 } while not in foreground
01-02 15:42:15.669: D/InCallScreen(242): onPhoneStateChanged()...
01-02 15:42:15.669: D/PhoneApp(242): updateWakeState: callscreen false, dialer false, speaker false, state OFFHOOK...
01-02 15:42:15.669: D/PhoneApp(242): setScreenTimeout(DEFAULT)...
01-02 15:42:15.669: D/PhoneApp(242): requestWakeState(SLEEP)...
01-02 15:42:15.669: D/InCallScreen(242): onPhoneStateChanged: Activity not in foreground! Bailing out...
01-02 15:42:15.669: I/StatusBarManagerService(167): UPDATE-null , 0x7f020143
01-02 15:42:15.669: I/StatusBarService(229): REMOVE:MiniCon-1
01-02 15:42:15.689: I/AlertDialog(5985): start stopping
01-02 15:42:15.699: I/StatusBarService(229): ADD:MiniCon-1
答案 0 :(得分:0)
我以不同的方式解决了这个问题。
- First I check if the person is in a call
- Then I check if the proximity sensor is activated
如果是这两种情况,则会从服务中播放声音。
然后我继续检查接近传感器是否已经停用(例如,手机是否是头部)。如果是这种情况,我的行为就会显示出来。