Show and run PWAs in custom launcher

Viewed 94

I am writing custom launcher and almost at the end of my work. I would like to have the functionality to add PWA to my launcher home screen.

I've created new activity that will handle new PWAs, added it to AndroidManifest with CONFIRM_PIN_SHORTCUT intent filter and managed to receive PinItemRequest in my activity when pwa got installed from browser.

AndroidManifest.xml

        <activity android:name=".HandleShortcutActivity">
            <intent-filter>
                <action android:name="android.content.pm.action.CONFIRM_PIN_SHORTCUT" />
            </intent-filter>
        </activity>

HandleShortcutActivity.kt:

class HandleShortcutActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            handlePins()
        }
        //LauncherApps.getPinItemRequest( this.intent );
    }


    @RequiresApi(Build.VERSION_CODES.O)
    private fun handlePins() {
        val launcherApps = applicationContext.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
        val request = launcherApps.getPinItemRequest(intent)

        Timber.d("handlePins: request = \n{shortcutInfo:\n\tlongLabel=${request.shortcutInfo?.longLabel}\n\tpackage=${request.shortcutInfo?.`package`}")

        this.finish()
    }

}

What information from shortcutInfo I can use to correctly run PWA from launcher? The package of PWA is com.android.chrome and it is accessible, but I can't see any additional info that could help me to run PWA.

Also, how can I get the icon from this received PinItemRequset which will I use as an icon in my launcher?

0 Answers
Related