Закрепленный ярлык Android "Приложение не установлено"

Я пишу приложение для запуска файлов JavaScript и пытаюсь добавить возможность закрепления ярлыка к файлу сценария на панели запуска.

Приложение в настоящее время работает, открывая .js файлы (через content://схема) из настраиваемого диалогового окна в приложении, а также из файлового браузера устройства; однако после закрепления ярлыка к файлу и щелчка по нему появляется всплывающее сообщение "Приложение не установлено".

Соответствующий код выглядит следующим образом:

AndroidManifest.xml

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INSTALL_SHORTCUT"/>
    <uses-permission android:name="android.permission.UNINSTALL_SHORTCUT"/>

    <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/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.BROWSABLE"/>
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="content"/>
                <data android:mimeType="*/*"/>
                <data android:pathPattern=".*\\.js"/>
                <data android:host="*"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.BROWSABLE"/>
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="file"/>
                <data android:mimeType="*/*"/>
                <data android:pathPattern=".*\\.js"/>
                <data android:host="*"/>
            </intent-filter>
        </activity>
    </application>

MainActivity.kt

    ...

    @RequiresApi(Build.VERSION_CODES.O)
    private fun createScriptShortcut() {
        val shortcutManager: ShortcutManager? = getSystemService(ShortcutManager::class.java)
        if (shortcutManager!!.isRequestPinShortcutSupported) {
            if (engine.currentFileUri == null) {
                return
            }

            val uri: Uri = engine.currentFileUri as Uri
            val intent = Intent(
                Intent.ACTION_MAIN,
                uri,
                this,
                MainActivity::class.java
            )
            intent.type = "*/*"
            intent.data = uri
            intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
            intent.`package` = "io.github.ascenderx.mobilescript"
            // TODO: Create fragment to let user customize shortcut label.
            val pinShortcutInfo: ShortcutInfo = ShortcutInfo.Builder(this, "scriptShortcut")
                .setIcon(Icon.createWithResource(this, R.drawable.ic_launcher_foreground))
                .setShortLabel(uri.toString())
                .setIntent(intent)
                .build()
            shortcutManager.requestPinShortcut(pinShortcutInfo, null)
        }
    }

    ...

Что мне не хватает? Это связано сpathPrefix или тип MIME (для которого .js файлов там явно нет на Android)?

0 ответов

Другие вопросы по тегам