안드로이드 앱에서 화면이 꺼졌을때 특정 처리를 해야 하는것들이 가끔 있는데 그거 하는 코드
public class MainActivity extends AppCompatActivity {
BroadcastReceiver screenOff = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
Log.d("linsoo", "화면 꺼짐");
//여기서 화면 꺼짐을 감지 하고 뭔가 처리를 한다
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//리시버 등록
IntentFilter offFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
registerReceiver(screenOff, offFilter);
}
@Override
public void onDestroy(){
super.onDestroy();
//리시버 해지
unregisterReceiver(screenOff);
}
}
public class MainActivity extends AppCompatActivity {
BroadcastReceiver screenOff = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
Log.d("linsoo", "화면 꺼짐");
//여기서 화면 꺼짐을 감지 하고 뭔가 처리를 한다
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//리시버 등록
IntentFilter offFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
registerReceiver(screenOff, offFilter);
}
@Override
public void onDestroy(){
super.onDestroy();
//리시버 해지
unregisterReceiver(screenOff);
}
}
public class MainActivity extends AppCompatActivity { BroadcastReceiver screenOff = new BroadcastReceiver(){ @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { Log.d("linsoo", "화면 꺼짐"); //여기서 화면 꺼짐을 감지 하고 뭔가 처리를 한다 } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //리시버 등록 IntentFilter offFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF); registerReceiver(screenOff, offFilter); } @Override public void onDestroy(){ super.onDestroy(); //리시버 해지 unregisterReceiver(screenOff); } }
답글 남기기