解锁屏幕时如何自动运行应用程序

问题描述 投票:0回答:1

我想在解锁屏幕时直接打开我的应用程序,我使用 ACTION_USER_PRESENT 但不使用我的代码,

ScreenReciver 文件

 public void onReceive(Context context, Intent intent) {

        Log.d(TAG,"||||||||||||||||||");
        System.out.println("Received broadcast: " + intent.getAction());
        System.out.println(":::::::::::::::::::::");
        if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)||intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)||intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
            Intent launchIntent = new Intent(context, MainActivity.class);
            launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(launchIntent);
        }


    }

manifest.xml

<receiver android:name=".ScreenReceiver"
            android:exported="true"  android:directBootAware="true">
            <intent-filter>
                <action android:name="android.intent.action.SCREEN_OFF" />
                <action android:name="android.intent.action.USER_UNLOCKED" />
                <action android:name="android.intent.action.SCREEN_ON" />
                <action android:name="android.intent.action.USER_PRESENT" />
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
            </intent-filter>
        </receiver>
java android flutter kotlin jquery-mobile
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.