[Android Studio] Screen permission options

Darcy Daeseok YU ·2022년 6월 12일
0

알람이 제때 실행될 때 화면 표시 옵션 설정

메소드를 만들어서 onCreate 메소드에 넣어도 되고

아래와 오버라이드해서 직접 넣는 방법도 있다.

// 잠금화면 위에 표시
    override fun onAttachedToWindow() {
        super.onAttachedToWindow()
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
            setShowWhenLocked(true)
            setTurnScreenOn(true)

            val keyguardMgr = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
            keyguardMgr.requestDismissKeyguard(this, null)
            window.addFlags(
                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                        or
                        WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
            )



        } else {


            window.addFlags(
                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED    // deprecated api 27
                        or WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD     // deprecated api 26
                        or WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                        or WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON   // deprecated api 27
                        or WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
            )

        }
    }

deprecated 된 항목이 꽤 된다.

모든 버전을 커버하기위해서 버전에 따라서 분기점을 만들어서 적용한다.

androidMainfest.xml 설정

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.yuds.notificationtest">


    <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
    <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
    <uses-permission android:name="android.permission.INTERNET" />
   

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.NotificationTest"
        android:usesCleartextTraffic="true">

        <receiver
            android:name=".AlarmReceiver"
            android:enabled="true"
            android:exported="true"></receiver>


        <activity
            android:name=".VideoAlarmAndNotifiActivity"
            android:exported="false"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            android:showOnLockScreen="true">
        </activity>


        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
profile
React, React-Native https://darcyu83.netlify.app/

0개의 댓글