웨이크 잠금 해제도 있음 :내 애플 배수 배터리 내가 PHONE_STATE을 수신 <code>BroadcastReciever</code>있는 간단한 응용 프로그램 짓고 있어요
<receiver android:name=".PhoneStateBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
을에서에게 BroadcastReciever
의 onRecieve()
상태가 OFFHOOK
때 나는 서비스를 시작 서비스에서
public class PhoneStateBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
String state = bundle.getString(TelephonyManager.EXTRA_STATE);
if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
context.startService(new Intent(context, ProximityService.class));
}
else if(state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
context.stopService(new Intent(context, ProximityService.class));
}
}
}
내가 근접 센서 리스너를 등록하고, WakeLock
그래서 화면이 잘 꺼집니다 만드는거야 : 상태가 IDLE
때와 서비스를 중지 전화 중일 때. 통화가 끝난 후 서비스가 중단되고 onDestroy()
에 청취자를 등록 해제하고 WakeLock
을 해제합니다. 하지만 내 앱 (30 %)에서 엄청난 배터리 소모가 발생하기 때문에 무언가가 출시되지 않는 것으로 보입니다. 리스너가 WakeLock
릴리스에도 등록을 취소 할 때
WakeLock
가 해제되는 것을 볼 수 있으며, 리스너는 (나는 또한 리스너가 등록되지 않은 것을
SensorManager
에서 로그를 볼 수 있습니다) 성공적으로 등록되지 않은 것입니다.
무엇이 여기에 있습니까? 그건 정말 짜증나.
서비스의 일부 코드 :
public int onStartCommand(Intent intent, int flags, int startId){
Log.d("CALL", "Service started");
// Get an instance of the sensor service, and use that to get an instance of
// a particular sensor.
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mProximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
mSensorManager.registerListener(this, mProximity, SensorManager.SENSOR_DELAY_NORMAL);
mAudioManager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
mPowerMngr = (PowerManager) getSystemService(Context.POWER_SERVICE);
try{
mWakeLock = mPowerMngr.newWakeLock(PROXIMITY_SCREEN_OFF_WAKE_LOCK, "Proximity");
if (!mWakeLock.isHeld()) {
Log.d("CALL", "Wake lock acquired");
mWakeLock.acquire();
}
}
catch (Exception e){
mWakeLock = null;
}
return START_STICKY;
}
public void onDestroy(){
super.onDestroy();
mSensorManager.unregisterListener(this);
if (mWakeLock != null) {
if (mWakeLock.isHeld()) {
Log.d("CALL", "Wake lock released");
mWakeLock.release();
}
}
Log.d("CALL", "Service stopped");
}
내가 볼 로그 :
09-30 03:35:09.120: D/SensorManager(21565): unregisterListener:: disable all sensors for this listener, listener = [email protected]
09-30 03:35:09.125: D/CALL(21565): Wake lock released
09-30 03:35:09.125: D/CALL(21565): Service stopped
감사합니다 많이! Elad