-1

こんにちは、アプリケーションの実行中にデバイスの画面を常にオンにしておく必要があります。電源ボタン機能を無効にして画面をオフにします。次のコードを試しました

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

とウェイクロック

@Override
public void onReceive(Context context, Intent intent) {
       if ((intent.getAction().equals(Intent.ACTION_SCREEN_OFF))) {

            PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
            wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "TEST");
            wakeLock.acquire();

            AlarmManager alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
            Intent inten = new Intent(context,NewActivity.class);
            PendingIntent pi = PendingIntent.getActivity(context, 0, inten, 0);
            alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,  100, pi);
            }
       }   

 // Finish your WakeLock HERE. call this method after U put the activity in front or when u exit from the new activity.
    public void finishWakeLocker(){
                  if (wakeLock != null) 
                  wakeLock.release();  
    }

前もって感謝します

4

1 に答える 1