2012-11-19 4 views
0

휴대 전화가 잠자는 동안 나는 (전화 벨소리 애니메이션과 비슷하게) 애니메이션 활동을 원합니다. 내 문제는Window 플래그를 통해 화면 켜기/끄기

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    this.getWindow().setFlags(
     WindowManager.LayoutParams.FLAG_FULLSCREEN | 
     WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | 
     WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON, 

     WindowManager.LayoutParams.FLAG_FULLSCREEN | 
     WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | 
     WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON 
    ); 

    setContentView(R.layout.act_image_activity); 
    startAnimation(); 
} 

:

이 나는 ​​창 관리자 플래그를 사용하여 화면을 회전에 관한 많은 글, 내 활동의에서 onCreate에이 코드 조각을 추가했다 않았다 그래서() 함수를 읽었습니다

  • 애니메이션은 약간의 지연으로 시작됩니다. 화면이 켜지면 키 가드 (또는 키 가드가 비활성화되었을 때 홈 화면)를 볼 수 있고 그 후에 내 활동이 시작됩니다.
  • 내 활동의 finish() 메소드를 호출 한 후 전화가 연결되지 않습니다. 잠을 자면, 잠자기 타이머가 다시 시작됩니다.

누군가가 화면이 켜진 후 즉시 애니메이션 활동을 표시하고 화면이 끝난 후 즉시 끄도록 할 수 있습니까?

+0

도움이되면 답변을 수락으로 확인하십시오. – Talha

답변

0

그러나이 리시버 매니페스트

<receiver android:name="IntentReceiver" > 
<intent-filter> 
    <action android:name="android.intent.action.SCREEN_ON" ></action> 
    <action android:name="android.intent.action.SCREEN_OFF" ></action> 
</intent-filter> 
</receiver> 

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.activity_main); 

     registerReceiver(new BroadcastReceiver() {       
     public void onReceive(Context arg0, Intent arg1) { 
      Log.v("tag", "screen on"); 
      // You can catch screen on here and start your animation 
     } 
     }, new IntentFilter(Intent.ACTION_SCREEN_ON)); 

     registerReceiver(new BroadcastReceiver() { 
     public void onReceive(Context arg0, Intent arg1) { 
      Log.v("tag", "screen off"); 
      // You can catch screen off here and start your animation 
      } 
     }, new IntentFilter(Intent.ACTION_SCREEN_OFF)); 
    } 
0

초기 지연과 키 가드의 일부를보고, 나는 그 것을 방지 할 수있는 방법이 있다고 생각하지 않습니다. 그러나 PowerManager.goToSleep을 호출하여 화면을 강제로 끌 수 있습니다.

+1

필요한 권한을 얻지 못했기 때문에 화면을 일반 앱으로 끌 수 없습니다. http://stackoverflow.com/questions/5710971/android-what -permissions-to-call-powermanager-gotosleepn-put-device-i – zapl

관련 문제