Why doesn't my Android 9 app open automatically on a TV screen after restart, while it works on the emulator?

69 Views Asked by At

AssistantReceiver.java

public class AssistantReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED))
            context.startActivity(context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()));
    }

}

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <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/Theme.App">

        <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>

        <receiver
            android:name=".AssistantReceiver"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

    </application>

</manifest>

When I restart the Android 9 emulator (It is TV screen), the app opens automatically because the receiver is functioning properly. However, when I try the same on a real Android 9 TV screen, the app does not open when I turn off and turn on again the screen, which suggests that the receiver might not be working. Could you please help me understand the reason for this discrepancy? Is there something that I might have missed?

1

There are 1 best solutions below

1
sdex On

Add the QUICKBOOT_POWERON action to your receiver:

    <receiver
        android:name=".AssistantReceiver"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />
        </intent-filter>
    </receiver>