BroadcastReceiver is not started after device boot

前端 未结 1 1991
日久生厌
日久生厌 2021-01-23 18:38

After device reboot, I want to run my receiver so that the device can play audio when the device screen is turned on or turned off without setting them manually through the app.

相关标签:
1条回答
  • 2021-01-23 18:57

    Define your manifest something like this.

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.dev.hb.testing">
    
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.RECORD_AUDIO" />
        <uses-permission android:name="android.permission.CAMERA" />
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <receiver android:name=".LockScreenReceiver">
                <intent-filter>
                    <action android:name="android.intent.action.BOOT_COMPLETED" />
                    <action android:name="android.intent.action.QUICKBOOT_POWERON" />
                </intent-filter>
            </receiver>
    
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
            <activity android:name=".WelcomeActivity" />
        </application>
    
    </manifest>
    
    0 讨论(0)
提交回复
热议问题